Vehicle Question

hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Vehicle Question

Post by hiker »

Hi all,

I have to change the position of a raycast vehicle after it has been created and added to the dynamics world. I tried the following code:

Code: Select all

    btTransform trans;
    trans.setOrigin(btVector3(m_reset_pos.xyz[0],
                              m_reset_pos.xyz[1],
                              m_reset_pos.xyz[2]+0.5*m_kart_height));
    m_kart_body->setCenterOfMassTransform(trans);
where m_reset_pos is a plib data structure with the start position of the kart (for now I have to add half the size of the kart to the Z-coordinate (up), since the rest of the program assumes that the Z-position of the kart is on the ground).

Problem is, that this doesn't really work - at the first stepSimulation() after the call, the kart will be flipped around (the X-axis), ending up with the wheels up in the air, and the front wheels at the back :?

Additionally, the manual states that the position of a dynamic rigid body should not be changed by the user :(

Unfortuantely, I have to change the vehicle position (when restarting a race) - otherwise I have to do quite a bit of restructuring, making the resulting code much harder to understand (destroying and recreating expensive objects).

Is there any way of doing changing a vehicle position 'correctly'? What about removing the rigid body from the dynamics world, changing the transformation, and adding it again? If this is correct, what about the vehicle which was added to the world as well??

Any recommendations appreciated!
Joerg
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Vehicle Question

Post by Erwin Coumans »

hiker wrote:Hi all,

Problem is, that this doesn't really work - at the first stepSimulation() after the call, the kart will be flipped around (the X-axis), ending up with the wheels up in the air, and the front wheels at the back :?

Any recommendations appreciated!
Joerg
You can set the worldtransform of a rigidbody, but it should be done carefully. Perhaps there is some issue with the Bullet Vehicle, I need to double check this and let you know.

Thanks,
Erwin
hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Re: Vehicle Question

Post by hiker »

Guess I found the problem: there was no setIdentity() done, and then trans had an invalid rotation. When I tried this code again today, it produced an assertion error when updating the wheels. After initialising the transform, it works.

Wouldn't it be better if the constructor would initialise a btTransform with an identical rotation instead of all zeros? Work-wise it would be the same: it is initialised with zeros at the moment, so initalising it with identity would be the same. Anyway, that's not urgent (though might be worth mentioning in the manual).

Thanks for the help!
Joerg