Dirso
23-07-2007 03:47:49
Hi,
I saw several posts about how to do a raycast car but no complete code. I'm not thinking about suspension and stuff, so far I just don't want the wheels to pass through the ground. Here is what I have done:
The car is supose to stop falling when the center of the is _radius units above the ground.
What am I doing wrong?
Thanks,
Dirso.
I saw several posts about how to do a raycast car but no complete code. I'm not thinking about suspension and stuff, so far I just don't want the wheels to pass through the ground. Here is what I have done:
void RayCastVehicle::allForcesCallback(OgreNewt::Body *me)
{
me->addForce(Ogre::Vector3(0,-9.8, 0) * _loader._carMass);
// for each wheel calculates all forces on each wheel
for(RayCastTireListIt it = _tires.begin(); it != _tires.end(); it++)
{
Ogre::Vector3 posWheel = (*it)->_wheelNodeNeutral->getWorldPosition();
Ogre::Vector3 start_pos, end_pos;
start_pos = end_pos = posWheel;
end_pos.y -= 3.0;
OgreNewt::BasicRaycast ray(mWorld, start_pos, end_pos);
OgreNewt::BasicRaycast::BasicRaycastInfo info = ray.getFirstHit();
if(info.mBody)
{
Ogre::Real dist = info.mDistance*3.0;
if(dist < (*it)->_radius)
{
me->addLocalForce(_loader._carMass*Ogre::Vector3(0,9.8/4.0,0), (*it)->_wheelSusAction->getPosition());
return;
}
}
}
}The car is supose to stop falling when the center of the is _radius units above the ground.
What am I doing wrong?
Thanks,
Dirso.