Thursday, July 14, 2016

Vehicle Physics (Godot 2D)

I've always been fascinated with the vehicle physics used in games. I played so many racing games / the hill climb games and every single time i would wonder wow that must be really hard to do.

Thanks to the new generation of game development tools, developing physics based games has become almost a second nature to most people. I didn't want to be left out so i gave it a shot..
I tried setting up vehicle physics in GoDot Engine for a 2D vehicle.

Here is what the vehicle scene looks like..

2D vehicle setup in GoDot
As you can see the body collision shape is not right but the rest of the stuff just works. The idea is simple think of what parts move along with the body vs what doesn't.

I was kinda stuck setting up the pinJoint2D in GoDot, it actually clearly takes two nodes under the properties. This makes sure that the wheels are hinged to the DampingSpring2D. The Damping Spring2D takes two physics bodies(Body and the PinJoint2D) and makes it work like shock absorbers.

You can see that under the panel for structure of the node setup.

you can checkout the code at.. github