Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tutorials/physics/ray-casting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------
Expand Down Expand Up @@ -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()``.