Page 1 of 1

How to set a rigid body in 3d position [SOLVED]

Posted: Thu Oct 16, 2014 11:03 am
by Alberto García
I'm programming a simple minigolf, game, and I try to set the ball ( rigid body ) in the 0,0,0 position when the ball Y position is < -1. This is my code:

Code: Select all

            
btVector3 position( 0, 0,0 );
this->ball->bulletRigid->getWorldTransform().setIdentity();
this->ball->bulletRigid->getWorldTransform().setOrigin(position);
But the sphere is not set on 0,0,0 instead of this the ball disappears.

Re: How to set a rigid body in 3d position [SOLVED]

Posted: Sat Oct 18, 2014 12:34 pm
by Alberto García
Hi have solved it by myself with the following code:

Code: Select all

            
btVector3 position( this->lastPostion.X( ), this->lastPostion.Y( ), this->lastPostion.Z( ) );
btTransform trans;
this->ball->bulletRigid->getMotionState()->getWorldTransform( trans );
trans.setOrigin( position );
this->ball->bulletRigid->clearForces();
this->ball->bulletRigid->setLinearVelocity( btVector3( 0, 0, 0) );
this->ball->bulletRigid->setAngularVelocity( btVector3( 0, 0, 0) );
this->ball->bulletRigid->setWorldTransform( trans );