# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Posted: Mon Apr 16, 2012 8:17 pm

Joined: Sun Apr 01, 2012 5:17 pm
Posts: 5
I've recently implemented a character controller, using the code from the Bullet charctercontroller demo.

Yet there's a somewhat strange problem:

The character has a speed and a rotation. When hitting the forward key it moves forward, when hitting the left key, it rotates left. When hitting both, forward and left, it will move a circle, i'll call it move-circle, finally arriving at the same position where it started.

It will do this move-circle in a counter-clockwise direction, when i hit the left key while moving forward. But the collisionshape rotates clockwise. And vice-versa, if i hit forward and right, the move-circle will be clockwise, as intended, but the collisionshape will rotate counter-clockwise. So basically the ghostobject and the collisionshape rotate in two different directions instead the same. This only applies to rotation, the position is correct.

The rotation is done with only this three lines of code, so actually only rotates the ghostobject:

Code:
btMatrix3x3 orn = mGhostObject->getWorldTransform().getBasis();
orn *= btMatrix3x3(btQuaternion(btVector3(0,1,0), dt * 1.57f));
mGhostObject->getWorldTransform ().setBasis(orn);

If i change the rotation to negative (e.g. by multiplying by -1.57f), the move-circle will change its direction, but also the collisionshape's rotation. So i don't manage to have the collisionshape rotate the same direction as the move-circle. But it should, in order to face the direction of the actual movement.

I can't figure out what i'm doing wrong, respectively how to change it to work right. Any ideas?

Thanks
whisp

Top

 Posted: Thu Apr 19, 2012 8:52 pm

Joined: Sun Apr 01, 2012 5:17 pm
Posts: 5
You will have to play it fullscreen to be able to see the collision-shape.

It might seem obvious to just rotate the ghostobject in the other direction in order to meet the collisionshape's rotation. This would however cause the ghostobject to move a clockwise circle while the collisionshape would start rotating left.

This is the code responsible for the movement:

Code:
void ControlledObject::doMovement(float deltaTimeS)
{
float dt = deltaTimeS;

if (mPhysics->getDynamicsWorld())
{
btTransform xform;
xform = mGhostObject->getWorldTransform ();

Ogre::Vector3 position = btToOgreV3(xform.getOrigin());

btVector3 forwardDir = xform.getBasis()[2];
btQuaternion rot = xform.getRotation();
forwardDir.normalize ();

btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
btScalar walkVelocity = btScalar(1.1) * 4.0; // 4 km/h -> 1.1 m/s
btScalar walkSpeed = walkVelocity * dt;

if (mLeft)
{

btMatrix3x3 orn = mGhostObject->getWorldTransform().getBasis();
orn *= btMatrix3x3(btQuaternion(btVector3(0,1,0), dt * -1.57f));
mGhostObject->getWorldTransform ().setBasis(orn);
}

if (mRight)
{
btMatrix3x3 orn = mGhostObject->getWorldTransform().getBasis();
orn *= btMatrix3x3(btQuaternion(btVector3(0,1,0), dt * 1.57f)); //Rotation in RAD (1.57 ~ 90°)
mGhostObject->getWorldTransform ().setBasis(orn);
}

if (mForward)
walkDirection += forwardDir;

if (mBackward)
walkDirection -= forwardDir;

mCharacter->setVelocityForTimeInterval(walkDirection*walkVelocity, dt );

mSceneNode->setOrientation(-rot.getW(), rot.getX(), rot.getY(), rot.getZ());
mSceneNode->setPosition(position);
}
}

Thanks for any hints.

whisp

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot], radubolovan and 5 guests

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

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities