Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Apr 28, 2012 9:28 am 
Offline

Joined: Sat Apr 28, 2012 9:25 am
Posts: 1
I've been suffering from an issue regarding the implementation of orienting characters in a game I'm implementing using Ogre3D and Bullet physics.
What I have: A Direction Vector that the character is moving in, along with its current orientation.
What I need: To set the orientation of the character to face the way it is moving.

I have a snippet of code that sort of does what I want:
Code:
btTransform src = body->getCenterOfMassTransform();
btVector3 up = BtOgre::Convert::toBullet(Ogre::Vector3::UNIT_X);
btVector3 normDirection = mDirection.normalized();
btScalar angle = acos(up.dot(normDirection));
btVector3 axis = up.cross(normDirection);
src.setRotation(btQuaternion(axis, angle));
body->setCenterOfMassTransform(src);


This snippet has a couple of problems however:

1) When changing direction, it tends to 'jitter' i.e. it rapidly faces one way, then the opposite for a second or so before correcting itself to the orientation it is supposed to be at.
2) Most times that the code is run I get an assertion error from Bullet's btQuaternion on
Code:
assert(d != btScalar(0.0));


Can anyone help?

Thanks!


Top
 Profile  
 
PostPosted: Sat Apr 28, 2012 3:04 pm 
Offline

Joined: Sun Jan 29, 2012 10:01 pm
Posts: 49
If your character is a round shape then you only need to rotate the visual representation.
By running backwards and sidestepping, your character can change direction using a fast acceleration while the direction is slowly turning to the walking direction.
The head can turn to the walking direction faster than the body because it don't have so much weight.

This is what it may look like:
http://www.youtube.com/watch?v=evol5XTgBnM


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group