# TestAdvancedVehicle

For all JMEPhysics 2.1 users out there. Here is my example of an advanced physics car, now better tuned and put together in a fancy test, with models, smoke and everything (except sound).

I’m thinking in evolving it to a new JMEPhysics tutorial series, where I start by explaining the car physics and go further to visual FX, Composing a track with checkpoints, developing AI for opponents and also Sound, if desirable.

Check out this example test here, it will be included in JMEPhysics CVS by Irrisor soon:

Downloadable source with models (needs CVS versions of JME and JMEPhysics 2):

www.infoway-pi.com.br/erick/TestAdvanceVehicle.zip

A screenshot:

PS.: It’s based on my code for the Dirty Racers game, so in the test you can have the same driving feels, at least for this car model.

have u given any thought to simulating transmission behavior can u share THOUGHTS on how to achieve it, if you have

thanks

Yes I have thought about it but didn't implemented yet. I'd go this way:

1 - I'd use (2nd grade?) math function to represent the power increase for the engine as the RPM goes up. This will just result in a float value for being used as availableAcceleration on the traction axis rotation.

2 - Create float values to represent the gears… This values will be used to simulate the gear relations by multiplying the result of the previous function:

3 - The RPM and gears can be calculated by a switch/case over the car linear speed for now (one can define a more refined function for that, maybe using states, based on acceleration flag and etc.)

Here it is (just the idea):

// I suplied a simple getLinearSpeed method. Can be changed to calculate linear speed based on rotational axis (X)

float enginePower = enginePower( getRPM(speed) ); // functions described above

int gear = getGear(speed); // described above

float gearRelation = getRelation(gear);

accelerate( enginePower * gearRelation ); // this will put dynamic acceleration on the wheels

I think this is a start. I'm trying to implement it right now and will post it in some minutes.

I’m not tthat good at computer math :’( but from what I know of cars " just a bit" there’s generally a slight loss of power at shift…turbo can mostly solve that  }:-@ … seriously though I’ll check this out at home.

thanks

OK, Implemented… Worked nice, but I’ll have to calibrate a bit yet. Don’t think should go to CVS but only in the upcaming racing tutorial I’ll write. I’m curious to test with my sound FX, where the pitch is dependant on the RPM.

Here is the updated sources with this more advanced example:

www.infoway-pi.com.br/erick/TestAdvancedVehicleEngine.zip

The old and more simple one is still here:

www.infoway-pi.com.br/erick/TestAdvanceVehicle.zip

PS.: It’s not a 2nd grade math function but square root (Math.sqrt(rpm)) that better approximate the power increase based on engine rpm.

Thanks Erick, this really is a great contribution!

I made some little changes (hope that's ok for you) and committed it to cvs.

I made some little changes (hope that's ok for you)

Of course it's ok.

I'm checking out from cvs now. What do you think about the tutorial series on a racing game?

For me an article about your findings while tuning the car(s) would be even more interesting. But I think there are more people who would appreciate that tutorial. (I remember at least 4 different people posting about cars with jME Physics 2 on these boards, so it's likely that there are even more trying to do cars)

Did you try the version with an engine simulation Kine? The link is up there. The version in CVS doesn

Thanks again Perick !  :lol:

All your tips helped me a lot …

nope ! I don't have time for merging into physic now … but I'll test it soon … no nitro in your engine I presume lol ? ok I'll pay attention

got back my internet service a couple days ago and started playing with this and i have some questions

1 where/how do adjust the steering responsiveness, the faster u go harder it is to steer, softening the suspension helps a little but not much, releasing the accelerator on turn also help but at the expense of some instability.

2 I had to split accelerate/braking/reverse into there own distinct actions/methods because the car slows faster when I release than when I brake :-o. I got more aggressive braking with:

```public void brake(final int direcao, float power) {         tractionAxis.setAvailableAcceleration((direcao * -power)*CarData.WHEEL_ACCEL*1000);         tractionAxis.setDesiredVelocity(0);     }```

nothing scientific :// just copied, pasted and threw numbers out until it looked right..............."in my eyes "

I even adjusted this block a bit

```public void releaseAccel(final int direcao, float power) {       tractionAxis.setAvailableAcceleration(CarData.WHEEL_ACCEL/1.25f);       tractionAxis.setDesiredVelocity(0);    }```

figured car still needed to power down a bit more rapidly

the problem stupidly enough, that has me stuck is getting my reverse to trigger only after the car has stopped.

3 there seems to be more to having a front / rear wheel drive vehicles than
/**
* Accelerates the car forward or backwards
* Does it by accelerating both suspensions (4WD). If you want a front wheel drive, comment out
* the rearSuspension.accelerate(direction) line. If you want a rear wheel drive car comment out the other one.
* @param direction 1 for ahead and -1 for backwards
*/

I tried that before I did anything else to the code but the car barely moves either way,  could explain a bit further. thank

but all in all this still a damn great example to work,

thank you very much
1 where/how do adjust the steering responsiveness, the faster u go harder it is to steer, softening the suspension helps a little but not much, releasing the accelerator on turn also help but at the expense of some instability.

The best tune I found was to set the Material for the wheels to have 1.25 in MU and 0.01 in bounciness. (default rubber-concrete is 0.9 and 0.5)

I agree with you about #2

Regarding #3 (front/rear traction cars):
I do it here just putting more available acceleration (try doubling it)...

And about the engine simulation I did a big mistake. The SQRT is not good for representing an engine's  increase in power by RPM because it's linear… The LOG math function is a better one.

How about storing torque curve as a set of points and then just interpolate between them? Would be easy then modify car characteristics without recompile.

One example here:

http://www.racer.nl/curved.htm

@perick

I have been able to spend more time modifying this recently, the plan is to get the basic mechanics working with test and then strip the the corresponding classes from dirty racers and tie in the changes. i have some questions.

1. can you indentify the classes needed the modify the test with any improvements, I think I know them just want to be certain the portugese 8).

2 as I said earlier I have broken braking and reverse into there own methods because I found that acceleration in the opposite direction produced weird result, instead I use  multiplied releaseAccel() method which seems to apply a much cleaner/stable stopping force.

whats catching me is the code to have reverse kick in after the vehicle completely stops inclusive of sliding that might occur after the wheels stop, plus  2 or 3 seconds  could  u offer some advice.

3 manual shifting can u offer a bit of advice.

on a side note I have also poked around in dirty racers the car handles a bit better if the wheels have more weight i.e. wheels + rims  the wheels don't get snagged on those invisible bumps in the road anymore (car appear to hit something but nothings there) …what cause that anyway.
1) can you indentify the classes needed the modify the test with any improvements, I think I know them just want to be certain the portugese

As in the test, which was extracted and translated from Dirty Racers classes, you should take a look at Car, Suspension and Wheel. They've the same semantics as in the test... Sorry for having coded that with portuguese method names.

#2 - That's nice... I'd like to put my tester hands on the improved version.

whats catching me is the code to have reverse kick in after the vehicle completely stops inclusive of sliding that might occur after the wheels stop, plus  2 or 3 seconds  could  u offer some advice.

If I understood right you could put a timer trigger that's initialized after the wheels stop (detectable by the 0 velocity). But I'm not sure here what's the desired effect.

#3 - Manual shifiting:
Use the LOG function (based on speed) + gear-relation (multiplier factor) as the engine power simulator.
Something like:
float availableAccel = FastMath.log(rpm)*gearMultiplier (1st higher multiplier, 5th lower multiplier)
RPM = speed/gearMultiplier;

Something like the above. Not sure about the right math, just ideas.

And last:
(car appear to hit something but nothings there) .............what cause that anyway.

Triangle collision issues in ODE. When a wheel misses some triangle edges it penetrates a bit in the terrain. I have tweaked a lot (it was worse than that) with triangle sizes, cfm, erp and material properties. What are my findings (you can test)
- Bigger triangles better
- Lower the material bounciness
- Some CFM can help
- More accuracy (simulation mode + at least 60fps) - if you use 100fps it gets even better of course.

Anyway. I'm not coding car games at the moment but I'd like to see your results. Are you using Dirty Racers source code? Did you try to create new Tracks? I can show you how to enable lap recording so you can create new Checkpoints in a newly created track.

Perhaps you can help Kine as wheel with Bolidz.

sorry for not getting back earlier had an exam

#2 - That's nice... I'd like to put my tester hands on the improved version.

I wont necessarily call it improved............yet, hard breaking is good, could still be tweaked, the car twists
somewhat I have been weighting the effects of the breaking on the rear suspension(given a fraction of the available braking force. if the car is in reverse pressing the accelerator sometimes makes it spin in the direction u are reversing and accelerates in that direction, rather than go forward again.

If I understood right you could put a timer trigger that's initialized after the wheels stop (detectable by the 0 velocity). But I'm not sure here what's the desired effect.

if I brake to stop. I want the car to stop for about 3 to 5 seconds before executing the reverse action "a pause mainly to clear/zero out all the forward momentum. some code/pseudo code idea would be very helpful to me with this.

#3 - Manual shifiting:
Use the LOG function (based on speed) + gear-relation (multiplier factor) as the engine power simulator.
Something like:
float availableAccel = FastMath.log(rpm)*gearMultiplier (1st higher multiplier, 5th lower multiplier)
RPM = speed/gearMultiplier;

o.k I'm not quite at that level yet unfortunately :'( but I taken programming a bit more seriously these days ...give me time... :mrgreen:

Are you using Dirty Racers source code?

not yet I'm using the test code with the shifting behavior

Did you try to create new Tracks? I can show you how to enable lap recording so you can create new Checkpoints in a newly created track.

that would be great really if u did that thanks

Perhaps you can help Kine as wheel with Bolidz.

I have seen bolidz, at my level I'd be useless to, kine but again hopefully maybe in time.

thanks for the advice though and help