Ogrenewt car moving too slowly

Kim2

22-08-2008 02:49:48

Hi guys.

A few problems I hope you can help me with.

I have a car that won't move fast enough. No matter how high I set the torque for the wheels it won't break 50km/h. What I mean to say is that the torque can be at 5000 or 50,000 and I get the same result. Everything is set up pretty default, just gave the car a mass of 1200kg. I thought it might be that the friction between the wheels and the ground is too low so I tried modifying it-


matPairDefault = new OgreNewt::MaterialPair( m_World, mMatDefault, mMatDefault );

matPairDefault->setDefaultFriction( 5.5, 5.4 );


But it didn't make any difference. Hopefully someone has experience with this kind of thing.

Second problem is that I am trying to delete the bodies of cars as they get a certain distance from the player but deleting the bodies is crashing my program.

void Car::DestroyPhysics()
{
std::vector< SimpleTire* > toDelete;

// delete tire objects.
for (SimpleTire* tire = (SimpleTire*)getFirstTire(); tire; tire=(SimpleTire*)getNextTire(tire))
{
toDelete.push_back( tire );
}

while (!toDelete.empty())
{
SimpleTire* tire = toDelete.back();
delete tire;
toDelete.pop_back();
}

//bod->freeze();
/*
// finally, destroy entity and node from chassis.
Ogre::Entity* ent = (Ogre::Entity*)((Ogre::SceneNode*)m_chassis->getOgreNode())->getAttachedObject(static_cast<unsigned short>(0));
((Ogre::SceneNode*)m_chassis->getOgreNode())->detachAllObjects();
((Ogre::SceneNode*)m_chassis->getOgreNode())->getCreator()->destroyEntity( ent );
((Ogre::SceneNode*)m_chassis->getOgreNode())->getParentSceneNode()->removeAndDestroyChild( m_chassis->getOgreNode()->getName() );
*/

delete bod;

physics = false;
}


I want to delete the physics body but leave the node. The commented out lines would remove the whole chassis node (including the mesh).


for(int k = 0; k < carVector.size(); k++)
{
float x = playerPos.x - carVector[k]->getPosition().x;
float z = playerPos.z - carVector[k]->getPosition().z;
float distance = sqrt(x*x + z*z);
if(distance > 50) {
if(carVector[k]->physics == true) {
carVector[k]->DestroyPhysics();
}

}
}

for(int k = 0; k < carVector.size(); k++)
{
if(carVector[k]->physics = true) {

// Rest of the AI...


I have the bool there to check if the physics body exists because there are calls that use it in the AI.



One more little problem, when I want to completely remove a car I tried:


for(int i = 5 ; i > 0; i--) {
carVector[i]->destroy();
carVector.erase(carVector.begin() + i - 1, carVector.begin() + i);
}


But this crashes the program as well. When I use carVector.clear() it works fine (but I want to clear only the index of the car that was destroyed, not the whole vector).

If anyone has experience with using the ogrenewt/Newton vehicles I'd like to hear about it. I was hoping to have around 30 cars spawning around the player (deleting them as they get too far away and respawning within a certain distance) but the performance seems to take a very big hit with each car added, regardless of the mesh complexity of the chassis and wheels. What I've decided to try is only making the very closest cars completely simulated (allowing for collision with the player) and faking the slightly more distant cars by just moving the nodes directly and animating the tires.

Thanks a lot for any help/advice.

Kim2

22-08-2008 09:09:53

Actually looking at the way the wheels are created, how exactly would you change the material for the wheels?

Kim2

23-08-2008 08:37:35

Well I managed to set the friction a little higher. I couldn't get the car to take on it's own material ID for some reason, though if it did work I guess setting a material ID for the chassis sets the ID for the whole vehicle (including the wheels).

Anyway I just left the car as default and gave the ground an ID. So now with the slightly increased friction the car can get up to 120km/h which is enough, but the car flips over very easily. To counteract this, what values should I be looking at modifying?

I see that there are a few things that can be set for the tires such as longitudinal slip coefficient but I don't really know what the ranges are for these values or what good values are for a realistic vehicle. I wonder if any of you guys could help me out with some examples or values that have worked well for you in the past?