Expose collider RID in 2D/3D kinematic collision

Can be useful to access the colliding body information for bodies
created with the physics server directly.
This commit is contained in:
PouleyKetchoupp 2021-06-09 18:24:15 -07:00
parent a33e0c2d41
commit a146e79758
6 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,9 @@
<member name="collider_metadata" type="Variant" setter="" getter="get_collider_metadata">
The colliding body's metadata. See [Object].
</member>
<member name="collider_rid" type="RID" setter="" getter="get_collider_rid">
The colliding body's [RID] used by the [PhysicsServer].
</member>
<member name="collider_shape" type="Object" setter="" getter="get_collider_shape">
The colliding body's shape.
</member>

View File

@ -21,6 +21,9 @@
<member name="collider_metadata" type="Variant" setter="" getter="get_collider_metadata">
The colliding body's metadata. See [Object].
</member>
<member name="collider_rid" type="RID" setter="" getter="get_collider_rid">
The colliding body's [RID] used by the [Physics2DServer].
</member>
<member name="collider_shape" type="Object" setter="" getter="get_collider_shape">
The colliding body's shape.
</member>

View File

@ -1392,6 +1392,9 @@ Object *KinematicCollision2D::get_collider() const {
ObjectID KinematicCollision2D::get_collider_id() const {
return collision.collider;
}
RID KinematicCollision2D::get_collider_rid() const {
return collision.collider_rid;
}
Object *KinematicCollision2D::get_collider_shape() const {
Object *collider = get_collider();
if (collider) {
@ -1422,6 +1425,7 @@ void KinematicCollision2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_local_shape"), &KinematicCollision2D::get_local_shape);
ClassDB::bind_method(D_METHOD("get_collider"), &KinematicCollision2D::get_collider);
ClassDB::bind_method(D_METHOD("get_collider_id"), &KinematicCollision2D::get_collider_id);
ClassDB::bind_method(D_METHOD("get_collider_rid"), &KinematicCollision2D::get_collider_rid);
ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicCollision2D::get_collider_shape);
ClassDB::bind_method(D_METHOD("get_collider_shape_index"), &KinematicCollision2D::get_collider_shape_index);
ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicCollision2D::get_collider_velocity);
@ -1434,6 +1438,7 @@ void KinematicCollision2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "local_shape"), "", "get_local_shape");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "collider"), "", "get_collider");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_id"), "", "get_collider_id");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "collider_rid"), "", "get_collider_rid");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "collider_shape"), "", "get_collider_shape");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_shape_index"), "", "get_collider_shape_index");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "collider_velocity"), "", "get_collider_velocity");

View File

@ -355,6 +355,7 @@ public:
Object *get_local_shape() const;
Object *get_collider() const;
ObjectID get_collider_id() const;
RID get_collider_rid() const;
Object *get_collider_shape() const;
int get_collider_shape_index() const;
Vector2 get_collider_velocity() const;

View File

@ -1335,6 +1335,9 @@ Object *KinematicCollision::get_collider() const {
ObjectID KinematicCollision::get_collider_id() const {
return collision.collider;
}
RID KinematicCollision::get_collider_rid() const {
return collision.collider_rid;
}
Object *KinematicCollision::get_collider_shape() const {
Object *collider = get_collider();
if (collider) {
@ -1365,6 +1368,7 @@ void KinematicCollision::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_local_shape"), &KinematicCollision::get_local_shape);
ClassDB::bind_method(D_METHOD("get_collider"), &KinematicCollision::get_collider);
ClassDB::bind_method(D_METHOD("get_collider_id"), &KinematicCollision::get_collider_id);
ClassDB::bind_method(D_METHOD("get_collider_rid"), &KinematicCollision::get_collider_rid);
ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicCollision::get_collider_shape);
ClassDB::bind_method(D_METHOD("get_collider_shape_index"), &KinematicCollision::get_collider_shape_index);
ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicCollision::get_collider_velocity);
@ -1377,6 +1381,7 @@ void KinematicCollision::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "local_shape"), "", "get_local_shape");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "collider"), "", "get_collider");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_id"), "", "get_collider_id");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "collider_rid"), "", "get_collider_rid");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "collider_shape"), "", "get_collider_shape");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_shape_index"), "", "get_collider_shape_index");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "collider_velocity"), "", "get_collider_velocity");

View File

@ -346,6 +346,7 @@ public:
Object *get_local_shape() const;
Object *get_collider() const;
ObjectID get_collider_id() const;
RID get_collider_rid() const;
Object *get_collider_shape() const;
int get_collider_shape_index() const;
Vector3 get_collider_velocity() const;