Object begins to rotate if using "setLinearVelocity"

Fred_FS
Posts: 10
Joined: Sun Sep 27, 2009 9:56 am

Object begins to rotate if using "setLinearVelocity"

Post by Fred_FS »

Hello,

I have an object which can be rotated by the player. But if the player rotates this object, it is not supposed to slow down an move slowly in the other direction, but it is supposed to use the velocity in the new direction.
So here is some code:

Code: Select all

float velocity = body_->getLinearVelocity().length();
	btVector3 new_velocity = BtOgre::Convert::toBullet( this->get_facing_direction() * velocity );
	body_->setLinearVelocity( new_velocity );
I get the length of the velocity vector of the object and calculate the new direction and set the linear-velocity in this direction.
But my object is not allowed to rotate around any axis except on the z-axis. So I used:

Code: Select all

body_->setAngularFactor( btVector3( 0, 0, 1 ) );
but if I use setLinearVelocity my object is rotating(after moving around) around the y- and x-axis.
But I don't understand why.

Is there any other way to realise what I want without using setLinearVelocity? Or do you have an idea why the object is rotating though setAnglarFactor is used?

Thanks for your help.