OgreNewt Vehicle Question

MLGKnox

12-04-2007 23:44:55

We are trying to place a simple vehicle into our game, so we figured the simple vehicle tutorial should suffice. The way it moves and turns is fine, but it hits a max speed of about 2. How do you make the car accellerate? Changing the torque we apply to the wheels has makes no change. Thanks for any info you can supply.

Tubez

12-04-2007 23:49:45

You should see a change if you increase the torque in the tutorial, but not a large one. The problem is that the wheels are slipping.
You can compensate for this by increasing the friction. Beware of "flipping over" problems though.

Also, depending on what kind of game you are making the vehicle joint may not be the best choice due to instabilities that occur at high velocities.
I solved this problem by moving to ray-cast based wheels.
See the wiki for more details:

http://walaber.com/newton_wiki/index.ph ... aycast_car

MLGKnox

13-04-2007 00:41:42

Thank you for the quick reply.

I apologize for my ignorance, but how would you go about increasing friction. Right now we have a mesh ground as a TreeCollision object and a single OgreNewt::Vehicle. To which object and how do I increase friction?

Tubez

13-04-2007 01:04:16

You create two materials and a material pair. You assign the materials to the objects, and the friction to the pair.

Apologising for the misnamings, my code looks like this (in python, but c++ should be similar):

self.matDefault = self.World.getDefaultMaterialID()
self.matCar = OgreNewt.MaterialID( self.World )
self.matFloor = OgreNewt.MaterialID( self.World )

self.MatPairDefaultCar = OgreNewt.MaterialPair( self.World, self.matFloor, self.matCar )

self.MatPairDefaultCar.setDefaultFriction( 1.0, 1.1 )

self.Car.chassis.setMaterialGroupID( self.matCar )
self.floor.setMaterialGroupID( self.matFloor )


For more information, see the demo with the conveyor belt. There they set the friction with the default material to make sure stuff stays on the belt.
Note that I cant vouch for the numbers. With raycast wheels my car floats above the ground. I have no idea if 1.0/1.1 is much or little friction.

unclepauly

13-04-2007 23:21:46

heres the code i use in my car app, its c++.


const OgreNewt::MaterialID* roadMaterial = mWorld->getDefaultMaterialID();
const OgreNewt::MaterialID* carMaterial = new OgreNewt::MaterialID(mWorld);
OgreNewt::MaterialPair* roadTyreFriction = new OgreNewt::MaterialPair(mWorld, roadMaterial, carMaterial);
roadTyreFriction->setDefaultFriction(1.0, 2.0);
m_chassis->setMaterialGroupID(carMaterial);


you can change the second param of setDefaultFriction to anything between 1 and 2.

but this isnt the only thing you can do. in your userCallback, you can also do:



for (Car::CarTire* tire = (Car::CarTire*)getFirstTire(); tire; tire = (Car::CarTire*)getNextTire( tire ) )
{
Ogre::Real load = tire->getNormalLoad();
Ogre::Real speed;

//tyre slip lateral
speed = tire->getOmega() * tire->getRadius();
tire->setMaxSideSlipSpeed(speed);
tire->setSideSlipCoefficient(speed * load * load);

//tyre slip longitudinal
speed = tire->getLongitudinalSpeed();
tire->setMaxLongitudinalSlipSpeed(speed);
tire->setLongitudinalSlipCoefficient(speed * load);

//rest of your code...
}


and that helps alot too.

MLGKnox

17-04-2007 22:51:04

Thanks for all of your help, I'll try it out. What we are trying to achieve is a Crazy Taxi type of feel where you can go fast and its responsive, but not necessarily reallistic with roll overs.

Tubez

18-04-2007 15:13:59

To avoid tipping over:

1) Lower your CoM.
2) If you are doign the car dynamics yourself, apply the forces a little higher than you normally would.

MLGKnox

19-04-2007 19:35:21

You guys are really helpful.

How would I go about doing the car dynamics myself?

Tubez

20-04-2007 09:54:18

For example with raycast wheels. See one of my first posts in this thread.

With physical wheels I experienced distressing numerical instabilities at high velocity. Abstracting away the wheels (and thus the source of the instability) seemed a logical choice.

If you are operating in a regime where this is not an issue, I'd stick to physical wheels.

unclepauly

21-04-2007 23:42:13

To avoid tipping over:

1) Lower your CoM.
2) If you are doign the car dynamics yourself, apply the forces a little higher than you normally would.


to get the com, you can do this:


OgreNewt::CollisionPrimitives::ConvexHull* col = new OgreNewt::CollisionPrimitives::ConvexHull(mWorld, carNode, false);
Ogre::Vector3 inertia;
Ogre::Vector3 com;
col->calculateInertialMatrix(inertia, com);
bod = new OgreNewt::Body(mWorld, col);
delete col;
bod->setMassMatrix(mass, inertia * mass);


so col->calculateInertialMatrix(inertia, com) returns the com. but yes, i found this was a little too high an dmmy car kept tipping over. if this happens, lower it like Tubex said, but know that if you lower it too far the car will lean forward when it accelerates instead of leaning back like it should. its like a boat, that has a really low com, which leans forward when it sails.

but if your taxi game isnt bothered about realism then i dont supposed it really matters!

ps there was a great car dynamics tutorial online which has now disappeared. you can use walabers stunt playground code though to see how its done properly, he released the source code for everyone to steal...

MLGKnox

24-04-2007 15:06:47

How would you recommend lowering the center of mass? The way I would think of doing it would be scale the Y portion of the vector, or would it be better to just subtract a vector of the form (0.0, -y, 0.0)?

Thanks again.