-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PhysicsDirectBodyState is singleton? #56245
Comments
@steelywing Can you reproduce this in GDScript instead of C#? |
Yes
Only |
That's indeed how this was designed... static BulletPhysicsDirectBodyState3D *get_singleton(RigidBodyBullet *p_body) {
singleton->body = p_body;
return singleton;
} Means the direct state will always be the last requested one. In GodotPhysics however, this seems to not be the case, as every body gets its own attached state object: GodotPhysicsDirectBodyState3D *GodotBody3D::get_direct_state() {
if (!direct_state) {
direct_state = memnew(GodotPhysicsDirectBodyState3D);
direct_state->body = this;
}
return direct_state;
} |
How do I work with 2 I cannot access |
I know, it's an implementation detail, a bad one though because it exploits a grey area of the documented behavior and is generally an unexpected behavior. If you want to use Bullet, the only workaround I see is to update the bodies one at a time, and not have both at the same time. Given your snippet, you could rewrite it like this: var r1 = PhysicsServer.body_get_direct_state($RigidBody.get_rid())
r1.linear_velocity += Vector3.FORWARD
# Done with r1
var r2 = PhysicsServer.body_get_direct_state($RigidBody2.get_rid())
r2.linear_velocity += Vector3.FORWARD
# done with r2 In more complex scenarios it might not be pretty but it's workable, you can get the state of any body but you can only hold one at a time. Otherwise this needs to be fixed because it is a nasty API hack... or you have to use GodotPhysics. |
Godot version
3.4
System information
Windows 10
Issue description
I get 2
PhysicsDirectBodyState
of 2PhysicsBody
usingPhysicsServer.BodyGetDirectState()
, but they became the same object.The doc doesn't mention this thing.
Steps to reproduce
Minimal reproduction project
_No response
PhysicsDirectBodyState.zip
_
The text was updated successfully, but these errors were encountered: