Godot Version
4.6
Question
Hello,
I am trying to get the CollisionShape3D that is hit when a get_world_3d().direct_space_state.intersect_rayis made.
The dictionary returned contains the collider key, which comes back to the RigidBody3D parent of the collider shape. The shapekey contains presumably an index to the shape that was hit in the CollisionShape3D. How do I reference this shape to the CollisionShape3D?
This is the function I am using to query:
func _send_ray_from_screen_to_world(screenPoint: Vector2) -> Dictionary:
var from = camera.project_ray_origin(screenPoint)
var to = from + camera.project_ray_normal(screenPoint) * ray_length
var ray_query = PhysicsRayQueryParameters3D.create(from, to)
var collision = get_world_3d().direct_space_state.intersect_ray(ray_query)
return collision
The code I tried to use, which doesn’t populate collision_area:
var collision = _send_ray_from_screen_to_world(event.position)
var collided_rb : RigidBody3D = collision["collider"] as RigidBody3D
var shape_id = collision["shape"]
var shape_owner_id = collided_rb.shape_find_owner(shape_id)
var collision_area : Shape3D = null
if shape_owner_id != 0:
# shape owner found
collision_area = collided_rb.shape_owner_get_shape(shape_owner_id, shape_id) as Shape3D
Thanks!