manual changing of orientation ignored for 1 frame

mike1
Posts: 14
Joined: Thu May 03, 2012 8:47 am

manual changing of orientation ignored for 1 frame

Post by mike1 »

Hi everyone,

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);
(newRotation is a vector I get from the client)

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
mike1
Posts: 14
Joined: Thu May 03, 2012 8:47 am

Re: manual changing of orientation ignored for 1 frame

Post by mike1 »

* bump *
does anyone have an idea for this? i'm getting desperate here.. :(
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: manual changing of orientation ignored for 1 frame

Post by Erwin Coumans »

Is is best to avoid the motion state when using server/client, and simply use the world transform from the rigid body directly.

Hope this helps,
Erwin