From 7c3a2002b7e5a99470c4e784eaf8825ca53b8698 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Sun, 15 Dec 2024 17:15:48 -0700 Subject: [PATCH] Free camera & shot projection collide with water --- project.godot | 2 +- src/player/shot_setup/shot_setup.gd | 2 +- src/player/shot_setup/shot_setup.tscn | 2 +- src/ui/3d/projectile_arc/projectile_arc.gd | 7 ++++++- src/ui/camera/free_camera/free_camera.tscn | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/project.godot b/project.godot index c988148..730f789 100644 --- a/project.godot +++ b/project.godot @@ -230,7 +230,7 @@ locale/translations=PackedStringArray("res://assets/text/text.en.translation") [layer_names] 3d_physics/layer_1="Collision Geometry" -3d_physics/layer_2="Layer 2" +3d_physics/layer_2="Water" 3d_physics/layer_27="Glass Material" 3d_physics/layer_28="Metal Material" 3d_physics/layer_29="Rock Material" diff --git a/src/player/shot_setup/shot_setup.gd b/src/player/shot_setup/shot_setup.gd index 1ed7502..25fc482 100644 --- a/src/player/shot_setup/shot_setup.gd +++ b/src/player/shot_setup/shot_setup.gd @@ -316,6 +316,7 @@ func _show_shot_projection() -> void: if not game_ball: return + shot_projection.set_ball(game_ball) shot_projection.putt_projection = club_type == Club.Type.PUTTER shot_projection.initial_speed = 1 shot_projection.basis = Basis.from_euler(Vector3(club.angle, 0, 0)) @@ -324,7 +325,6 @@ func _show_shot_projection() -> void: tween.tween_property(shot_projection, "initial_speed", shot_speed, CAMERA_SNAP_TIME).set_trans( Tween.TRANS_QUAD ) - shot_projection.linear_damp = game_ball.linear_damp shot_projection.show() diff --git a/src/player/shot_setup/shot_setup.tscn b/src/player/shot_setup/shot_setup.tscn index f6f4cc2..77a9918 100644 --- a/src/player/shot_setup/shot_setup.tscn +++ b/src/player/shot_setup/shot_setup.tscn @@ -574,7 +574,7 @@ loop_animation = 1 [node name="ShotProjection" parent="ArrowPivot" instance=ExtResource("4_ry2ho")] unique_name_in_owner = true -transform = Transform3D(1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107, 0, -0.02, 0) +transform = Transform3D(1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107, 0, 0, 0) visible = false initial_speed = 50.0 time_step = 0.1 diff --git a/src/ui/3d/projectile_arc/projectile_arc.gd b/src/ui/3d/projectile_arc/projectile_arc.gd index d6a7928..8517bbb 100644 --- a/src/ui/3d/projectile_arc/projectile_arc.gd +++ b/src/ui/3d/projectile_arc/projectile_arc.gd @@ -27,7 +27,7 @@ const PUTT_ATTRITION := 0.8325 # green? ## Uses continuous collision detection. @export var check_collision := true ## Mask for collision checking. -@export_flags_3d_physics var collision_mask := 1 +@export_flags_3d_physics var collision_mask := 1 | 2 ## Bodies excluded from collision checking. ## This should probably include the ball! @export var excluded_bodies: Array[CollisionObject3D] = [] @@ -61,6 +61,11 @@ var _cached_vel: Vector3 @onready var debug_draw: Control = %DebugDraw +func set_ball(ball: GameBall) -> void: + global_position = ball.global_position + linear_damp = ball.linear_damp + + func _process(_delta: float) -> void: if not visible: # Don't bother if we're not visible diff --git a/src/ui/camera/free_camera/free_camera.tscn b/src/ui/camera/free_camera/free_camera.tscn index 449997c..6db7a28 100644 --- a/src/ui/camera/free_camera/free_camera.tscn +++ b/src/ui/camera/free_camera/free_camera.tscn @@ -7,6 +7,7 @@ [node name="FreeCamera" type="CharacterBody3D"] process_mode = 3 collision_layer = 0 +collision_mask = 3 script = ExtResource("1_3gm3q") [node name="CollisionShape3D" type="CollisionShape3D" parent="."]