Problem with wheels on btRaycastVehicle

Spoonfork
Posts: 2
Joined: Sat Feb 20, 2010 6:20 pm

Problem with wheels on btRaycastVehicle

Post by Spoonfork »

I've been experimenting with btRaycastVehicle for a few hours now and I'm having some truly annoying problems. For some reason the wheels just go straight through the btStaticPlaneShape that I have acting as ground, but the chassis behaves as expected.

This is how I'm creating the vehicle:

Code: Select all

m_pBoxShape = new btBoxShape(btVector3(1.f,0.75f,2.1f));

btTransform chassisLS;
chassisLS.setIdentity();
chassisLS.setOrigin(btVector3(0,0.5f,0));

m_pCompoundShape = new btCompoundShape();
m_pCompoundShape->addChildShape(chassisLS,m_pBoxShape);

btDefaultMotionState* pMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,2,0)));
btScalar mass = 800;
btVector3 intertia;
m_pBoxShape->calculateLocalInertia(mass, intertia);

btRigidBody::btRigidBodyConstructionInfo bodyInfo(mass, pMotionState, m_pCompoundShape, intertia);
bodyInfo.m_friction = 0.6f;
bodyInfo.m_restitution = 0.6f;
bodyInfo.m_linearDamping = 0.2f;
bodyInfo.m_angularDamping = 0.2f;

m_pBody = new btRigidBody(bodyInfo);
m_pBody->setActivationState(DISABLE_DEACTIVATION);

btRaycastVehicle::btVehicleTuning tuning;

tuning.m_maxSuspensionTravelCm = 500.0f;
tuning.m_suspensionCompression = 4.4f;
tuning.m_suspensionDamping = 2.3f;
tuning.m_frictionSlip = 1000.0f;
tuning.m_suspensionStiffness = 20.0f;

m_pVehicleRaycaster = new btDefaultVehicleRaycaster(m_pDynamicsWorld);
m_pVehicle = new btRaycastVehicle(tuning,m_pBody,m_pVehicleRayCaster);

m_pDynamicsWorld->addRigidBody(m_pBody);
m_pDynamicsWorld->addAction(m_pVehicle);

m_pVehicle->setCoordinateSystem(0,1,2);

btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
btScalar suspensionRestLength = 0.6f;
btScalar wheelRadius = 0.5f;
btScalar connectionHeight = 0.2f;

{
	btVector3 connectionPointCS0(0.88f,connectionHeight,1.6f);
	m_pVehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,tuning,true);
}
{
	btVector3 connectionPointCS0(-0.88f,connectionHeight,1.6f);
	m_pVehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,tuning,true);
}
{
	btVector3 connectionPointCS0(0.88f,connectionHeight,-1.6f);
	m_pVehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,tuning,false);
}
{
	btVector3 connectionPointCS0(-0.88f,connectionHeight,-1.6f);
	m_pVehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,tuning,false);
}

for(int32 i = 0; i < m_pVehicle->getNumWheels(); ++i)
{
	btWheelInfo& rWheel = m_pVehicle->getWheelInfo(i);

 	rWheel.m_suspensionStiffness = 20.0f;
	rWheel.m_frictionSlip = 1000.0f;
	rWheel.m_rollInfluence = 0.1f;
	rWheel.m_wheelsDampingCompression = 4.4f;
	rWheel.m_wheelsDampingRelaxation = 2.3f;
}
I've double and triple checked the appVehicleDemo-example and I also checked out the OgreBullet-wrapper's Vehicle-example, but without luck. I found this link which said that it could be because the suspension can't support the weight of the vehicle, but I tried changing the chassis' mass to 1 and it didn't really change anything.

Is there some obvious mistake I'm making?
Spoonfork
Posts: 2
Joined: Sat Feb 20, 2010 6:20 pm

Re: Problem with wheels on btRaycastVehicle

Post by Spoonfork »

Right, it seems you can't use btStaticPlaneShape to raycast against. I wish I'd tried a rigid body or something a bit earlier.

Over and out.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Problem with wheels on btRaycastVehicle

Post by Erwin Coumans »

Spoonfork wrote:Right, it seems you can't use btStaticPlaneShape to raycast against. I wish I'd tried a rigid body or something a bit earlier.

Over and out.
The btStaticPlaneShape might not support raycast yet, this shape type isn't often used in game (but just for demo purposes). We should add ray cast support soon, it is trivial.

Thanks for the report,
Erwin