btKinematicCharacterController and strafing

Zern
Posts: 4
Joined: Fri Jun 03, 2011 3:21 am

btKinematicCharacterController and strafing

Post by Zern »

Greetings,

As with most, I am very new to Bullet Physics (actually just downloaded it and integrated this past Thursday) and have been working on getting it to work as desired.

My issue comes with the strafing of my Character Controller.

I can get my controller to properly rotate however when I want to strafe that's where things get funky.


When I rotate my character I use the following code:

Code: Select all

	
btQuaternion rot = m_pCharacter->getGhostObject()->getWorldTransform().getRotation();
rot *= btQuaternion(btVector3(0,1,0), btScalar(0.001f * y)); // (y is  just a positive 1 or negative 1 to dictate which direction to rotate)

m_pCharacter->getGhostObject()->getWorldTransform().setRotation(rot);

after I rotate I use the following code:

Code: Select all

float rotY = m_pCharacter->getGhostObject()->getWorldTransform().getRotation().getAngle();
Now here is where things get funky ... starting at radian 0.00 if I go clockwise (+0.001f increments), rotY goes from 0.000 up to 4.18 and then jumps to 2.19!!!! And yet if I continue clockwise with the above code (y = positive 1), rotY goes down from 2.19 to 0 .. at which point starts incrementing correctly (0.0 -> 0.01 -> 0.02 etc) until it hits 4.18 and then repeats ...

If I go clockwise starting at 0.000, this time y = -1 rotY goes from 0.0 -> up to 2.19 and then jumps to 4.18 ... and then continues down from 4.18 until 0.0 is hit.

For some odd reason it seems like there is an issue with the values 4.19 -> 5.99 and I have no idea why.



My strafe code works properly until this 'patch' is hit.

If anyone has any ideas I welcome them even if just thoughts of what might be going wrong! :)


Thank you.
Kanttori
Posts: 38
Joined: Thu Jul 08, 2010 12:52 am

Re: btKinematicCharacterController and strafing

Post by Kanttori »

The numbers you supply are a bit "off" for this theory (would expect a sum of ~6.28), but I thought you might want to check the direction of the rotation axis. Looks like you're going from quaternion to matrix and back to a quaternion again so maybe the rotational axis gets flipped in the process.
Last edited by Kanttori on Sun Jun 05, 2011 2:51 pm, edited 1 time in total.
marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am

Re: btKinematicCharacterController and strafing

Post by marios »

Quaternions are weird:) have you tried using matrices instead of quaternions? I think it's simpler. Code like this:

Code: Select all

float y,p,r;
transform.getBasis().getEulerYPR(y,p,r);
transform.getBasis().setEulerYPR(y+0.002f,p,r); //add some angle to axis you want
Last edited by marios on Fri Aug 12, 2011 12:22 am, edited 3 times in total.
Zern
Posts: 4
Joined: Fri Jun 03, 2011 3:21 am

Re: btKinematicCharacterController and strafing

Post by Zern »

Kanitori and marios, thank you both for the ideas and suggestions. :) Definitely going to try them out in a few, thank you again!