Hi, I'm using Ogrenewt for my physics engine and I'm having problem integrating the simplevehicle class to my game. The problem is my jeep/car just keeps on sliding against the surface as if it's in space regardless of its mass, suspensions, etc. I've changed different variables multiple times but it had no effect on the slipperiness of the wheels. I even modified the core newton script so I can directly control the wheels through code but none of it helped. I had to revert all the changes because it didn't solve the problem anyway. Can you help me out please?
I also made different materials for my terrain and the car chasee and applied 2.0 friction to both elements.
I commented it out. The sliding problem subsided but now I don't have suspension on my car.
I know for sure that AddSingleSuspensionTire has something to do with the sliding problem. Because previously when I flip the car it stops sliding, but if I flip it over in normal position, it starts to slide. So the sliding is related to the wheels.
I'm also looking at this bit of disabled code (commented out) in the same file, it looks like it has something to do with preventing the car from sliding sideways, the problem is the code doesn't compile, there's a lot of undeclared identifier errors and I don't want to mess up the code, I might end up messing the whole project.
// Apply brake, need some little fix here. // The fix is need to generate axial force when the brake is apply when the vehicle turn from the steer or on sliding. if ( tire.m_breakForce > 1.0e-3f ) { _ASSERTE (0); /* // row constrained force is save for later determine the dynamic state of this tire tire.m_isBrakingForceIndex = constraintIndex; constraintIndex ++;
// there is a longitudinal force that will reduce the lateral force, we need to recalculate the lateral force tireForceMag = lateralFrictionForceMag * lateralFrictionForceMag + tire.m_breakForce * tire.m_breakForce; if (tireForceMag > (frictionCircleMag * frictionCircleMag)) { lateralFrictionForceMag *= 0.25f * frictionCircleMag / dSqrt (tireForceMag); } */ }
So I decided I could make this work by modifying the submitConstraint fucntion in DGRayCast file. I want to get rid of the x and z movements and leave the y alone to get the spring effect. Getting rid of the x & z means the car won't move anywhere else other than up and down, this also means getting rid of the sliding problem. To move the car I would manipulate the car manually by adding force to the chasee. The problem is I don't know which bits to modify to get rid of the x & ys in the matrix. Here's the code I cleaned up straight from Newton lib's CustomDGRayCastCar.cpp
void CustomDGRayCastCar::SubmitConstraints (dFloat timestep, int threadIndex){
// get the vehicle global matrix, and use it in several calculations dMatrix bodyMatrix; NewtonBodyGetMatrix (m_body0, &bodyMatrix[0][0]); dMatrix chassisMatrix (m_localFrame * bodyMatrix);
// get the chassis instantaneous linear and angular velocity in the local space of the chassis dVector bodyForce; dVector bodyOmega; dVector bodyVelocity;
// calculate all suspension matrices in global space and tire collision dMatrix suspensionMatrix (CalculateSuspensionMatrix (i, 0.0f) * chassisMatrix);
// calculate the tire collision CalculateTireCollision (tire, suspensionMatrix, threadIndex);
// calculate the linear velocity of the tire at the ground contact tire.m_tireAxelPositGlobal = chassisMatrix.TransformVector (tire.m_harpointInJointSpace - m_localFrame.m_up.Scale (tire.m_posit)); tire.m_tireAxelVelocGlobal = bodyVelocity + bodyOmega * (tire.m_tireAxelPositGlobal - chassisMatrix.m_posit); tire.m_lateralPinGlobal = chassisMatrix.RotateVector (tire.m_localAxisInJointSpace); tire.m_longitudinalPinGlobal = chassisMatrix.m_up * tire.m_lateralPinGlobal;
// now calculate the tire load at the contact point // Tire suspension distance and hard limit. dFloat distance = tire.m_suspensionLenght - tire.m_posit; _ASSERTE (distance <= tire.m_suspensionLenght); tire.m_tireLoad = - NewtonCalculateSpringDamperAcceleration (timestep, tire.m_springConst, distance, tire.m_springDamper, suspensionSpeed ); if ( tire.m_tireLoad < 0.0f ) { // since the tire is not a body with real mass it can only push the chassis. tire.m_tireLoad = 0.0f; }
//this suspension is applying a normalize force to the car chassis, need to scales by the mass of the car tire.m_tireLoad *= (m_mass * 0.5f);
// convert the tire load force magnitude to a torque and force. // accumulate the force doe to the suspension spring and damper tire.m_tireForceAcc += chassisMatrix.m_up.Scale (tire.m_tireLoad);
// axle linear speed dFloat axelLinearSpeed = tireHubVeloc % chassisMatrix.m_front;
// calculate the formal longitudinal force the tire apply to the chassis dFloat longitudinalForceMag = CalculateLongitudinalForce (i, axelLinearSpeed, tire.m_tireLoad * tire.m_groundFriction);
// accumulate the longitudinal force dVector tireForce (tire.m_longitudinalPinGlobal.Scale (longitudinalForceMag)); tire.m_tireForceAcc += tireForce;
// now we apply the combined tire force generated by this tire, to the car chassis dVector r (tire.m_tireAxelPositGlobal - chassisMatrix.m_posit);
// add the toque the tire asserts on the car body (principle of action reaction) dVector torque (r * tire.m_tireForceAcc - tire.m_lateralPinGlobal.Scale (tire.m_torque)); NewtonBodyAddForce (m_body0, &tire.m_tireForceAcc[0]); NewtonBodyAddTorque( m_body0, &torque[0] );
} else {
// there is a next torque on the tire tire.m_torque -= tire.m_angularVelocity * tire.m_Ixx * DG_TIRE_VISCUOS_DAMP; tire.m_angularVelocity += tire.m_torque * tire.m_IxxInv * timestep; if (m_tires[i].m_breakForce > dFloat (0.1f)) { tire.m_angularVelocity = 0.0f; } }
// spin the tire by the angular velocity tire.m_spinAngle = dMod (tire.m_spinAngle + tire.m_angularVelocity * timestep, 3.14159265f * 2.0f);
The problem is that in DGRayCast is very old, I do not even thonk David is using any more, he is using the latest Newton Ogre Newton and I think he made his own DGRayCast tah seem vey cool https://www.youtube.com/watch?v=PLXBh85PL7E what do you just use that version?
I use a multibody custom joint in my demo, it's not a raycast vehicle. I don't have get the time to test DGRayCast again, I need to update my code for try this one.
1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(77) : error C3861: 'NewtonVehicleTireIsAirBorne': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(80) : error C3861: 'NewtonVehicleTireLostSideGrip': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(83) : error C3861: 'NewtonVehicleTireLostTraction': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(86) : error C3861: 'NewtonVehicleGetTireOmega': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(89) : error C3861: 'NewtonVehicleGetTireNormalLoad': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(92) : error C3861: 'NewtonVehicleGetTireSteerAngle': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(95) : error C3861: 'NewtonVehicleGetTireLateralSpeed': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(98) : error C3861: 'NewtonVehicleGetTireLongitudinalSpeed': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(104) : error C3861: 'NewtonVehicleSetTireTorque': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(107) : error C3861: 'NewtonVehicleSetTireSteerAngle': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(110) : error C3861: 'NewtonVehicleTireCalculateMaxBrakeAcceleration': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(113) : error C3861: 'NewtonVehicleTireSetBrakeAcceleration': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(116) : error C3861: 'NewtonVehicleSetTireMaxSideSleepSpeed': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(119) : error C3861: 'NewtonVehicleSetTireSideSleepCoeficient': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(122) : error C3861: 'NewtonVehicleSetTireMaxLongitudinalSlideSpeed': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(125) : error C3861: 'NewtonVehicleSetTireLongitudinalSlideCoeficient': identifier not found 1>C:\Dev\OgreNewt\newton20\inc\OgreNewt_Vehicle.h(179) : error C3861: 'NewtonVehicleReset': identifier not found
Apparently the errors can be fixed by downgrading to Newton 1.53. But I'm afraid it might cause set backs on my OgreNewt codes.
the problem is that you have a version of the engine that is so old no one has it the latest newton has a nice cool vehicle. but since no one maintain the Newton Ogre wrapper you are stocked with an old version.
I tried once to make an Ogre Wrapper but the people over Ogre do not want anything to with Newton, or with me particularly, they prefer libraries that the think will give the more notoriety any one who dare to say anything positive about newton get bat mouse and scorned out of the forum.so I decide to focus my attention on other projects.
if you want here is a Ogre wrapper the use Newton 3.13 which gas a nice vehicle, you can try that but you will have to make some change on your side. https://code.google.com/p/ogrenewton
Thank you, I'll check it out. Despite what everyone says I think OgreNewt & Newton are very flexible compared to PhysX & Bullet (I haven't tried Ode yet). NxOgre has a faulty player controller and the tutorials aren't exactly 1:1 copy of the tutorials provided by PhysX. Bullet doesn't even compile.
That later version is more flexible and it works more like Ogre that the original OgreNewton. It be eassy for you to get it to go because it will be like working in Ogre.
It also do a few things that the original did not like frame interpolations.