Rotation of a character to alter its orientaiton

Post Reply
Brian Beuken
Posts: 21
Joined: Sat Jul 29, 2017 9:19 pm

Rotation of a character to alter its orientaiton

Post by Brian Beuken » Fri Aug 04, 2017 9:04 pm

I am having a bit of an issue with rotation, I want to spin a character on the spot to allow him to choose his direction of travel, but from the point of his creation as a rigidBody, I can find no methods to alter his orientation once created.

The btMotionstate allows me to gain access to the report data after a Physics step has occurred so I can comfortably alter his visual position and orientation for render, but as far as physics is concerned he still exists and points at the values he was given on creation.

Is there no other way to spin a character other than applying torque or setting Angular Velocity until orientation is where you want it?

ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Re: Rotation of a character to alter its orientaiton

Post by ktfh » Sat Aug 05, 2017 4:10 am

use btCollisionObject::setWorldTransform if you want to alter position or orientation, example:

Code: Select all

btQuaternion newrotation(0,0,0,1);
object->setWorldTransform(btTransform( newrotation, object->getWorldTransform().getOrigin()));

Brian Beuken
Posts: 21
Joined: Sat Jul 29, 2017 9:19 pm

Re: Rotation of a character to alter its orientaiton

Post by Brian Beuken » Sat Aug 05, 2017 2:32 pm

thank you I'll try that.

Edit...thank you that worked a treat I have now created 2 small utility functions in my Physics Object class to make it a little cleaner to use in game.

As I found this hard to locate in a search I will post this here for any others like me who are new to Bullet.



Code: Select all

// couple of useful utility methods to simplify the rotate and position of our physics objects 
// these act on the Rigid body and therefore will re-position/orient an object while it is
// in the physics world, useful for restarting or teleporting.
	inline void SetOrientation(btQuaternion Rotation)
	{
		GetRigidBody()->setWorldTransform(btTransform(Rotation, GetRigidBody()->getWorldTransform().getOrigin()));
	}

	inline void SetPosition(btVector3 Position)
	{
		GetRigidBody()->setWorldTransform(btTransform(GetRigidBody()->getOrientation(), Position));
	}

Keywords Position, Rotation, Orientation.

Post Reply