Skip to content

Commit b360bbc

Browse files
Include collide_with_areas in ray-casting.rst (godotengine#7449)
Co-authored-by: Raul Santos <[email protected]>
1 parent a736e3b commit b360bbc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tutorials/physics/ray-casting.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,24 @@ data:
151151
metadata: Variant() # metadata of collider
152152
}
153153

154-
The data is similar in 3D space, using Vector3 coordinates.
154+
The data is similar in 3D space, using Vector3 coordinates. Note that to enable collisions
155+
with Area3D, the boolean parameter ``collide_with_areas`` must be set to ``true``.
156+
157+
.. tabs::
158+
.. code-tab:: gdscript GDScript
159+
const RAY_LENGTH = 1000
160+
161+
func _physics_process(delta):
162+
var space_state = get_world_3d().direct_space_state
163+
var cam = $Camera3D
164+
var mousepos = get_viewport().get_mouse_position()
165+
166+
var origin = cam.project_ray_origin(mousepos)
167+
var end = origin + cam.project_ray_normal(mousepos) * RAY_LENGTH
168+
var query = PhysicsRayQueryParameters3D.create(origin, end)
169+
query.collide_with_areas = true
170+
171+
var result = space_state.intersect_ray(query)
155172

156173
Collision exceptions
157174
--------------------
@@ -278,6 +295,5 @@ To obtain it using a camera, the following code can be used:
278295
}
279296
}
280297

281-
282298
Remember that during ``_input()``, the space may be locked, so in practice
283299
this query should be run in ``_physics_process()``.

0 commit comments

Comments
 (0)