Tuesday, 21 October 2014

Racing prototype - Physics breakdown






So here I've got my two first prototypes for a racing game that I'm working on, and want to breakdown how the physics currently works. Mostly because I want to keep note of it, and I'm planning to replace it with a (hopefully) better and less CPU heavy system.



Space dust racing was a game I looked at when working out my vehicle physics, they have a pretty good breakdown of how it all works, or at least the theory behind it. So this was a good starting point for me to base my  scripting around.

So, here's how it works. I draw four ray traces down in local z space.  It then grabs the contact point and divides it into the length of the raycast to give a number between 1 and 0 which is then scaled by a factor and applied as a force at the source of the raycast.

It also takes the upwards velocity of the vehicle into account during theese calculations and attempts to dampen it to remove the perpetual bounciness that the system was giving me in early testing.

The Blueprint that handles the suspension system.

The acceleration is simply handled by setting the vehicles velocity in its local orientation by an incrementing amount when the forwards/backwards buttons are pressed. To stop it from accelerating to an infinite amount the vehicle has linear velocity dampening enabled, which is also what causes it to come to a stop when there isn't any force being applied.

The blueprint that handles acceleration

To simulate traction, the vehicle gets the forwards velocity of the vehicle then gets the Y component  of the vector, scales it by an amount and then applies a force in the opposite direction of the Y vector.

The blueprint that handles traction.


The current setup also has some other features such as a sstabilizerarray that rotates the vehicle if it starts to tip over too far. A lot of the functions in the system are also vetted by an "is airborne" check which simply detects via a ray trace if there is a surface directly underneath the vehicle, which allows me to alter physics settings depending on the vehicles state, That ray trace also finds out what phsyical material is under the vehicle, allowing me to do things such as lowering the tracion on certain sufaces.

The blueprint that handles the stabilizer array

No comments:

Post a Comment