From 2aac9d9a1a35eeae19465432162d37e06b5d91e9 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Feb 2018 16:32:27 -0500 Subject: [PATCH] Revert "Remove ray and use Camera.project_position(" This reverts commit f41676c6725fb9b7ceb063df2abfc634624fb9f4. I misunderstood the way the camera projections work, and I'm better off using the original raycasting strategy. --- scenes/player.tscn | 10 +++++++++- scripts/heroes/1.gd | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scenes/player.tscn b/scenes/player.tscn index ba9aa93..0f36847 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -20,7 +20,7 @@ radial_segments = 64 rings = 8 _sections_unfolded = [ "Resource" ] -[node name="RigidBody" type="RigidBody" groups=[ +[node name="RigidBody" type="RigidBody" index="0" groups=[ "player", ]] @@ -98,6 +98,14 @@ near = 0.05 far = 100.0 _sections_unfolded = [ "Transform", "Visibility" ] +[node name="Ray" type="RayCast" parent="Yaw/Pitch" index="1"] + +enabled = true +exclude_parent = true +cast_to = Vector3( 0, 0, -100 ) +collision_mask = 1 +_sections_unfolded = [ "Transform" ] + [node name="MeshInstance" type="MeshInstance" parent="." index="4"] transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.95, 0 ) diff --git a/scripts/heroes/1.gd b/scripts/heroes/1.gd index 81be711..daa8087 100644 --- a/scripts/heroes/1.gd +++ b/scripts/heroes/1.gd @@ -23,10 +23,10 @@ func _process(delta): if is_placing_wall: # Find the point we're looking at, and put the wall there var aim = get_node("Yaw/Pitch").get_global_transform().basis - var camera = get_node("Yaw/Pitch/Camera") - var pos = camera.project_position(Vector2()) + var look_ray = get_node("Yaw/Pitch/Ray") + var pos = look_ray.get_collision_point() placing_wall_node.set_translation(pos) - var towards = camera.project_ray_normal(Vector2()) + pos + var towards = look_ray.get_collision_normal() + pos var up = -aim[2] # Wall should be horizontal to my view placing_wall_node.look_at(towards, up)