In my game I'm running Bullet in both server & client.
In this game each character has an orientation and state (which is Standing / Walking / Running). A character can only walk forward (forward is defined by the character's orientation).
The server receives a state from the client, including information about orientation (where the character is looking at) and the server is using this information to apply forces etc.
The problem I'm facing at the moment is as following:
In the beginning, the client rests and does nothing. It's orientation is towards -Z axis.
When the user hits the 'D' button on the keyboard, what should happen is that the player will immediately face towards +X axis and start moving there. So a packet containing the new state is received on the server, and I'm using the following code to rotate the object:
Code: Select all
LOG( "Updating physics rotation of object " + Strings::Convert(m_Object->GetObjectId()) + " to " + Strings::Convert(newRotation), CLogger::Levels::Debug );
btTransform transform = RigidBody->getWorldTransform();
transform.setRotation( BltUtils::Convert(newRotation) );
RigidBody->setWorldTransform(transform);
So far - so good. However, in the next physics step I get a notification through a btMotionState that the rotation is changed back to what it was before the physics step. This only happens once, and when I override the orientation again it doesn't change. However, since it happens for 1 frame, I get funny behaviors.
Why is that, and how can I fix this?
Notes:
1. I'm not setting the rotation while inside the physics step
2. I know setting orientation directly isn't recommended, and I'm OK with 'explosions' happening due to that at the moment
Any help will be greatly appreciated!
Thanks,
Mike