Weird error in btRaycastVehicle?

charles_west
Posts: 11
Joined: Mon Oct 19, 2009 12:41 am

Weird error in btRaycastVehicle?

Post by charles_west »

I am implementing a Ogre/Bullet application and getting a very strange error involving the btRaycast vehicle. I have checked my code several times, but I can't seem to find anything that would cause this.

The problem is intermittent, but the general pattern is that the btRaycastVehicle that I am working with will work fine as long as I move it within a few seconds of the application starting. If I move it, it works beautifully. If I wait, it will not budge, despite successful messages from the lines exerting it. The relevant code is this:

This is the update function. It gets called every cycle and passed the elapsed time (inputTime). User actions set the targetEngineForce, which is applied until the maxSpeed is reached, then the brake slows it down again.

Code: Select all

if(fabs(palletJackBotVehicle->getCurrentSpeedKmHour())>(maxSpeed*3.6))
{
printf("0 Speed control: Setting the engine force to: %f\n",0.0);
for(int i=0; i<4; i++)
{
palletJackBotVehicle->applyEngineForce(0,i);
}
}
else
{
printf("1 Speed control: Setting the engine force to: %f\n",targetEngineForce);
for(int i=0; i<4; i++)
{
palletJackBotVehicle->applyEngineForce(targetEngineForce,i);
}
}

printf("I'm updating! Vehicle speed is: %f\n",palletJackBotVehicle->getCurrentSpeedKmHour());
palletJackBotVehicle->updateVehicle(inputTime);


I tend to suspect my code far more then Bullet's, though I have checked and this is the only portion of code that touches the force settings.
Does anyone know what might be going on?
charles_west
Posts: 11
Joined: Mon Oct 19, 2009 12:41 am

Re: Weird error in btRaycastVehicle?

Post by charles_west »

It turns out that the source of the error is that the btRaycastVehicle class does not call activate on the btRigidBody associated with the vehicle. Consequently, the btRaycastVehicle applies force but the vehicle does not move. If I may ask, is there a reason why the btRaycastVehicle class doesn't call activate on its btRigidBody member?
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Weird error in btRaycastVehicle?

Post by mi076 »

It turns out that the source of the error is that the btRaycastVehicle class does not call activate on the btRigidBody associated with the vehicle.
Disable deactivation (here from VehicleDemo)

Code: Select all

//never deactivate the vehicle
m_carChassis->setActivationState(DISABLE_DEACTIVATION);

Code: Select all

palletJackBotVehicle->updateVehicle(inputTime);
As far as i know you don't need updateVehicle (called from btRaycastVehicle::updateAction).
Call applyEngineForce / setBrake before step simulation.