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-
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.
I want to delete the physics body but leave the node. The commented out lines would remove the whole chassis node (including the mesh).
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:
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.
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.