Car physics

Blitz3D Forums/Blitz3D Programming/Car physics

Chimeara(Posted 2005) [#1]
Ok, i'm making a racing game....(like many others)i've been slowly improving it and releasing new versions, I have your average gravity code but i would like to implement some code that allows the car to tilt as it goes over jumps, so that it is parralell with the surface it is driving on when going up and down hills. but unforturnetly i have stuck for ideas of how to code this.


KuRiX(Posted 2005) [#2]
Well i think that in these days you should look for a physics library to make that kind of things.

Look for ODE, Tokamak, Newton, in the Userlibs forum.

A physics library let you use rigid bodies dynamic system to control cars, boxes, ragdolls, etc...


Vorderman(Posted 2005) [#3]
Try using 4 linepicks to align to the ground (see the Blitz DRIVER demo program for this).

I've got a system where the car is aligned to the floor using linepicks, until the difference between the previous vertical position and the current vertical position becomes too great (for example as the car crests a hill) - at this point, the car is given an upwards vertical velocity that matches the incline of the hill (worked out from the difference value mentioned before). The car then has a GRAVITY value added to the vertical velocity each frame so it starts to drop back to earth. Once it hits the ground you can either have it bounce a bit (reverse the vertical velocity and multiply it by 0.95 or 0.8 or something) or you can just revert to the linepicks to orient it to the ground it's landed on. It's not ODE-perfect but it does work.


Rob Farley(Posted 2005) [#4]
The problem with only using vertical velocity is that if the car ends up 90 degrees either on it's side or end it all goes pear shaped.


Vorderman(Posted 2005) [#5]
Why's that?

I have the bodyshell parented to a central pivot, so it can be moved and rotated seperately.

I've put a limit on the bodyshell rotation, so it can't go past about 30 degrees nose up or down.

It's not a full physics system - you can't roll the car - but it does look pretty good as the car leaps over crests. It's more of an arcade system rather than a simulation - if you want full-on rolling and pitching etc.. then ODE is your best bet.


Jeremy Alessi(Posted 2005) [#6]
You can also put nodes on the roof so that if it goes more than 90 degrees it bounces back on it's wheels. Although, I think using ODE at this point looks good. Tokamak was ok but a bit lose ... the friction wasn't good and you couldn't use cylinders for tires ... so the car could slide sideways etc...

I developed the beginnings of a decent vehicle physics engine without the help of a library because all the physics libs seemed unstable but since ODE works with Blitz again, the Cygnus demo which uses ODE looks like the best thing for vehicle physics.


Rook Zimbabwe(Posted 2005) [#7]
Vorderman (Posted 2005-02-24 09:06:53)

Try using 4 linepicks to align to the ground (see the Blitz DRIVER demo program for this).

I have been playing with a demolition derby ieda for a few months... I didn't even think of that!!! Linepick for the wheels... D'OH!!!
-RZ


poopla(Posted 2005) [#8]
A combo of what vorderman mentioned and a decent verlet system could be successful.


Stevie G(Posted 2005) [#9]
I tried the jacobsons verlet but it's not very good for track inclines ... the cage kind of jerks around. I'll need to post some code over the weekend in my other thread and see if anyone can suss where I'm going wrong. I really don't want to loose the subtle rolling etc..

I would recommend taking a look at Vorderman's stunt car remake ... the physics code looks like a straight conversion from Maco Munsters c code but I think it handles pretty well and is solid.

Stevie


cyberseth(Posted 2005) [#10]
A very simple way to do this is to have 4 pivots, one for each of the wheels, and give each one xyz velocity variables that move independently, all affected by gravity etc. Then, you use code like that in the "driver" demo (samples\mak folder) to align the car to the pivot positions, and then snap the pivots to the wheel position.


Damien Sturdy(Posted 2005) [#11]
ODE is realy easy to use once you get used to it. I havent managed to use the newer wrappers yet; Arkons one jiggled around alot without reason, Apprently he has fixed this, but im at work and havent been able to find it.

JV ODE looks great, I should get a few mins to play with it at some point.

it would be nice to wrap a new ode wrapper to the older commands so that the older projects can be upgraded and continues :)


my_name_is_alex_hello__(Posted 2005) [#12]
Using linepick and setting specific things to happen when the car reaches an incline or whatever is more of a hack job than car physics. You have to frickin use some equations or somthing, use where the wheels want to go based on collisions with the ground to move the body of the car or whatever

i might have a go at it now, i know its not simple because ive tried it before.

ALSO, i think that using a physics libary is a cop out. Make ure own.


Vorderman(Posted 2005) [#13]

Using linepick and setting specific things to happen when the car reaches an incline or whatever is more of a hack job than car physics.



perhaps, but there is still a physics system behind it that controls the movement of the car when on the ground - my current system allows for controllable power-oversteer and full-on drifting, but also allows for variations in the car such as front and rear-wheel drive, mass, inertia etc.. I've now got it checking the ground polys also so that mud/gravel is more slippery than tarmac.


Stevie G(Posted 2005) [#14]
@ Alex yeah you're right I agree that using a 3rd party physics lib is a cop out but hacks such as what Vorderman is using are unavoidable in my opinion. Good gameplay is paramound so a bit of fudging is always required. If you're planning on writing a GT4 equiv then I suggest you forget about Blitz. However, I'm sure the whole community would be interested in your results .. if you get that far.

Look forward to seeing this finished Vorderman ... I remember downloading the old version not long after I bought Blitz3d ...... get your finger out!!! ;)


Vorderman(Posted 2005) [#15]
Just posted a Blitz Rally demo here -
http://www.blitzbasic.com/Community/posts.php?topic=44265
for you to have a look at.