diff options
author | Paul Joannon <hello@pauljoannon.com> | 2022-08-14 10:09:35 +0200 |
---|---|---|
committer | Paul Joannon <hello@pauljoannon.com> | 2022-08-22 09:18:08 +0200 |
commit | 6bc0be16a54862af2f75c8ed12109c079349ad17 (patch) | |
tree | d0efc51759e69284ac730fb31d45b657a0776ea2 /scene/2d/ray_cast_2d.cpp | |
parent | 0c5f254956f0115e363ce08045dd178dc30b54f8 (diff) |
Expose the collider RID in Raycast nodes
Create and expose the method `get_collider_rid` in `RayCast2D` and `Raycast3D`.
This method returns the `RID` of the first object that the ray intersects, or an empty `RID` if no object is intersecting the fay (i.e. `is_colliding` returns `false`).
Diffstat (limited to 'scene/2d/ray_cast_2d.cpp')
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 68e5ffdcf9..c4036faa79 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -82,6 +82,10 @@ Object *RayCast2D::get_collider() const { return ObjectDB::get_instance(against); } +RID RayCast2D::get_collider_rid() const { + return against_rid; +} + int RayCast2D::get_collider_shape() const { return against_shape; } @@ -203,12 +207,14 @@ void RayCast2D::_update_raycast_state() { if (dss->intersect_ray(ray_params, rr)) { collided = true; against = rr.collider_id; + against_rid = rr.rid; collision_point = rr.position; collision_normal = rr.normal; against_shape = rr.shape; } else { collided = false; against = ObjectID(); + against_rid = RID(); against_shape = 0; } @@ -321,6 +327,7 @@ void RayCast2D::_bind_methods() { ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast2D::force_raycast_update); ClassDB::bind_method(D_METHOD("get_collider"), &RayCast2D::get_collider); + ClassDB::bind_method(D_METHOD("get_collider_rid"), &RayCast2D::get_collider_rid); ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast2D::get_collider_shape); ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast2D::get_collision_point); ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast2D::get_collision_normal); |