Raycast Vehicle problem

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:
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.

Dirso

23-07-2007 03:56:25

BTW:
1) I have only one rigid body (for the bodycar). The wheels are not rigid body.
2) I'm not using any joints, I don't think I'll need it at all.

Dirso.

walaber

23-07-2007 05:08:12

i don't see anything too obvious... can you explain what happens more closely?

Dirso

23-07-2007 20:53:27

Looks like I had a design problem on that. Because when I add the force (0,9.8/4.0,0) I actually cancel the aceleration but the car keeps its velocity down to the ground. So I'll need to make the suspension to force the car up. If you have made anything like this before and could post a few samples it would be really nice.

Thanks,
Dirso