Public Group

# simplified car dynamics

This topic is 4003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi im doing a topdown 2d game with driving in various vehicle as part of the game. Im going for a simplified approach, has gotten some stuff to work simply by:

//vel
vel=master.transmission[ddd.unit[type].gears][gear]*rpm*0.15f;

//add vel to actual speed of vehicle
speed.x+=(vel)*sin(rot)*0.01;
speed.y+=-(vel)*cos(rot)*0.01;

//friction from ground
speed.x*=terrainFriction[currentGround];
speed.y*=terrainFriction[currentGround];

//update position
pos.x+=SPEED*speed.x;
pos.y+=SPEED*speed.y;


you acc/deacc by changing the RPM and changing gear. I turn a vehicle by simply rotating the vehicle due to sertain restrains (position of wheels/speed etc). 1.The vehicle slides nicely in turns but how can i scale the slide-ness of different wheels/terrain into my code? If i change terrainFriction[x] that will greatly change maximum speed and acceleration. I just want it to "effect grip". 2.Also how can i revert the process so i take two floats (for example speed.x and speed.y) and output a "speed and angle" from these two floats? 3. Gears simply work by adding to velocity like currentGearStrenght*rpm. Shifting gear is restricted so it seems to work. Is this too crappy or do you think it will work in a very simplified racing-game? Thanks E

##### Share on other sites
hi Suliman, I tried some car physics stuff a few years back, but it was quite difficult and really only managed to get turning etc done, so you've already done better than I did. It is really hard to understand to start with though.

Have you had a look at the marco motors resources someone posted in a different thread? I haven't had a look at the link as I still have those resources (if they are the same ones), from when I tried it, and its pretty much all there for 2d car stuff.

From what I remember (and I have just had another look at marco's implementation), you are meant to treat the side and forward forces differently. I think side forces increase as you turn etc. They also "act" around the centre of mass - like a centrifrugal force. When that goes above a certain point thats when you start sliding.

I would forget gears for now to be honest, as they just add complications, (and aren't going to affect getting it working), you could add them back in once everything else is working.

What language are you using? What graphics api?

##### Share on other sites
c++ with hge engine.

Yeah ive read that one i maybe thats what i need to do to be able to scale the slipperyness but that impementation includes a lot of stuff i dont understand...

the gears work pretty ok and now i also have a reverse gear.

No way to easily modify my code so slipperyness can be controlled?
E

##### Share on other sites
I think that if you want to simulate a slipperiness based on Newtonian mechanics, you can't just get a speed for x and y, and be done with that. You'll have to work with 2d vectors to do this. That is, treat all forces, acceleration and velocity as vectors, with a size and a direction. Doing this and reading up on centrifugal forces, should bring you in the position to create adjustable slipperiness.

Secondly, slipperiness is a rather broad term. It can divided in two categories, namely understeer and oversteer.
From wikipedia:
Understeer is a term for a car handling condition during cornering in which the circular path of the vehicle's motion is of a markedly greater diameter than the circle indicated by the direction its wheels are pointed.
Oversteer is a phenomenon that can occur in an automobile which is attempting to turn. The car is said to oversteer when the rear wheels do not track behind the front wheels but instead slide out toward the outside of the turn. Oversteer can throw the car into a spin.

The first is rather identical to classical examples of centrifugal forces (as a matter a fact, my schoolbook about physics even talks about cars making turns). To get a rudimentary slipperiness working, this could be enough.

##### Share on other sites
Spinning etc isnt needed. i only need the slipperyness like:
0 % tank-moving no matter what velocity the vehicla has
20% normal (some sliding in curves etc)
80% ice (vehicle more or less "continue" forward no matter the rotation)

No way to achieve this with my very simplified physics-model above?

E

##### Share on other sites
I assume that, in order to turn a vehicle, you just change rot. You could try to limit the amount the rotation can be changed within a certain timeframe. This should be dependant on the terrain, the vehicle and the velocity of the vehicle.

You could make a function to this for you:
float MaxRotate(float terrainFriction, float wheelFriction, float velocity)
{
float ret;
//hoever you wish to get a maximum turn in degrees out of the three parameters
//The idea is, the higher the terrain and wheel friction and the lower the
//velocity, the higher the maximum rotation is.
return ret
}

and then use it like this
rot+= MaxRotate(terrainFriction[currentGround], wheelFriction[currentWheel], vel)
to go right and
rot-= MaxRotate(terrainFriction[currentGround], wheelFriction[currentWheel], vel)
to go left.
So you,ll need another array for wheel friction.

[EDIT]
Oh, as for the second question in your original post. What you describe is converting between Cartesian and polar coordinates. Check this wikipedia page for a section called "Converting between polar and Cartesian coordinates". I believe it contains everything you need.

[Edited by - atRoot on August 6, 2007 9:24:12 AM]

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002291
×