From b360bbc40bde30d151e38e30a40e54ba6220e3f5 Mon Sep 17 00:00:00 2001 From: Angad Singh Josan <97420031+ajosan25@users.noreply.github.com> Date: Fri, 2 Jun 2023 03:31:28 -0700 Subject: [PATCH] Include collide_with_areas in ray-casting.rst (#7449) Co-authored-by: Raul Santos --- tutorials/physics/ray-casting.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tutorials/physics/ray-casting.rst b/tutorials/physics/ray-casting.rst index 4992dd327..7741ae9b5 100644 --- a/tutorials/physics/ray-casting.rst +++ b/tutorials/physics/ray-casting.rst @@ -151,7 +151,24 @@ data: metadata: Variant() # metadata of collider } -The data is similar in 3D space, using Vector3 coordinates. +The data is similar in 3D space, using Vector3 coordinates. Note that to enable collisions +with Area3D, the boolean parameter ``collide_with_areas`` must be set to ``true``. + +.. tabs:: + .. code-tab:: gdscript GDScript + const RAY_LENGTH = 1000 + + func _physics_process(delta): + var space_state = get_world_3d().direct_space_state + var cam = $Camera3D + var mousepos = get_viewport().get_mouse_position() + + var origin = cam.project_ray_origin(mousepos) + var end = origin + cam.project_ray_normal(mousepos) * RAY_LENGTH + var query = PhysicsRayQueryParameters3D.create(origin, end) + query.collide_with_areas = true + + var result = space_state.intersect_ray(query) Collision exceptions -------------------- @@ -278,6 +295,5 @@ To obtain it using a camera, the following code can be used: } } - Remember that during ``_input()``, the space may be locked, so in practice this query should be run in ``_physics_process()``.