Car Physics

Blitz3D Forums/Blitz3D Programming/Car Physics

Nate the Great(Posted 2008) [#1]
I have been making my own car physics for a game and came across a huge problem. My physics engine is a verlet based one that I made myself and I know it works. the problem occurs if you ram into something at high speeds, it will invert your car so the top acts like the wheels and the bottom acts like the top so you end up driving upside down. You will see what I mean because I made each verlet a transparnet sphere.

Here is the code. sorry if it is long and not very well commented.




Please does anyone know what is happening and why? I have no clue


Pongo(Posted 2008) [#2]
This is something that can happen with verlet physics.

What happens is that one of your verlets has moved too far, and a different solution has been found.

Imagine a pyramid. If the top point is moved down too far, the solution found may be an upside down pyramid. This is still a valid solution for all the constraint lengths, just not the one you want. Generally speaking, the more complex the verlet cage, the easier it is to "break" like this. Another bad situation happens when the constraints end up competing for each other and can't satisfy the proper lengths. This results in the verlet group going crazy and usually spinning wildly out of control.

What you need to do is one or several of the following.
- take smaller simulation steps
- move things slower
- create a more solid cage that cannot break as easily. More constraints is not necessarily the answer,... they have to be in the correct places. My most stable cages are made of triangles and tetrahedrons. I have several variations that I cannot break within the limits of my game engine.


Nate the Great(Posted 2008) [#3]
That is what I was thinking but I wasn't sure. The speed required to make the cages invert was not my intended game speed but I was just curious. I don't think this will be a problem later on considering there won't be much to run into at that high a speed.


Stevie G(Posted 2008) [#4]
IMO, if you're using a verlet integration method for physics then it's a must that you have functions to detect the inversion and correct it before it's visible to the user. You can pretty much guarantee that it will happen at some point, especially when you start to simulate body/body collisions correctly.

For example, imagine 2 vehicles racing at full speed and hitting each other head on. Even if they are travelling at a slow speed their relative speed will likely be large enough for them to interpentrate and cause inversion ro worse still entaglement.


Nate the Great(Posted 2008) [#5]
Ok I will try to do that it looks as though this will take longer than I expected thanks :)


Nate the Great(Posted 2008) [#6]
I have been messing with the car wheel physics and ran into a big problem. There is something wrong with parenting the wheels to the car and then rotating them. you'll see what I mean if you run this code.




Stevie G(Posted 2008) [#7]
Use scalemesh instead of scaleentity

tmpcar = CreateCube()
ScaleMesh tmpcar,1,.1,2
EntityColor tmpcar,20,100,255


As soon as you parent something to a scaled entity it adopts that scale

Also do this ..

tmpwheel = CreateCylinder(5)
RotateMesh tmpwheel,0,0,90
ScaleMesh tmpwheel,.2,.4,.4
EntityColor tmpwheel,10,10,10
EntityRadius tmpwheel,.3
MoveEntity tmpwheel,0,-.7,0



Nate the Great(Posted 2008) [#8]
thnx stevie g it worked.


Ridil(Posted 2008) [#9]
So what would the best method for detecting inversion in a verlet system be? I've seen lots of places where people say that's what needs to be done but none which say how to do it (efficiently)