Archive 17/01/2023.

RigidBody2D z position defaulting to 0

miz

I am trying to move a RigidBody2D’s z position.

void Player::SetZ(int z) { position.z_ = z; playerNode->SetPosition(position); }

But after I do, SetLinearVelocity() seems to force it back to 0. When I do not have SetLinearVelocity it keeps it’s z position. But if I do manual movement with something like position+=velocity collisions stop working :frowning:

Anyone know how I could get around this?

Thanks :slight_smile:

thebluefish

RigidBody2D works only on the X/Y axis (hence the 2D). I’m not surprised that attempting to use the Z-axis is not working.

miz

Is there a way then to disable all rotation so that I can use RigidBody a bit like RigidBody2D?

codingmonkey

all “Angular factors” to zero
or/and get world position of rigidbody and project it into some plane.

miz

Oh, I found it. SetAngularFactor(Vector3(0,0,0)) will stop a RigidBody from rotating.

Now I just need to see if I can make 3D rigid bodies collide with 2d ones?..

thebluefish

3D physics and 2D physics are done with two different physics engines, so a RigidBody will never interact with a RigidBody2D. If you need 2D physics in 3D space, you’ll want to do everything as 3D physics.

Modanung

…and rigidBody_->SetLinearfactor(Vector3::ONE - Vector3::UP); for a top-down game.