How to get RigidBody RID?

Godot Version

4+

Question

I’m trying to get a RigidBody’s PhysicsDirectBodyState, and to do that I wanted to try to use PhysicServer.body_get_direct_state(body: RID), but to do that, I first have to get the RigidBody’s RID. How can I do that?
Thanks in advance!

You can use get_rid() to get the RID from your RigidBody.

Alternatively, you can override the _integrate_forces function in your rigidbody to get the state.

It worked! Thanks a lot!
But… I’m pretty new to godot so could you explain what do you mean by overriding the _integrate_forces function?

From the documentation:

void _integrate_forces(state: PhysicsDirectBodyState2D) virtual
Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default, it is called before the standard force integration, but the custom_integrator property allows you to disable the standard force integration and do fully custom force integration for a body.

You can put the _integrate_forces(state) function in your script just like the _ready() function and it will work as described above (at the end of every frame)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.