Include collide_with_areas in ray-casting.rst (#7449)

Co-authored-by: Raul Santos <raulsntos@gmail.com>
This commit is contained in:
Angad Singh Josan
2023-06-02 03:31:28 -07:00
committed by GitHub
parent a736e3b9cb
commit b360bbc40b

View File

@@ -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()``.