Quantcast
Channel: BinaryTides » Box2d
Viewing all articles
Browse latest Browse all 8

Make a racing car using Box2d in javascript

$
0
0
Racing car in box2d
Box2d is a physics 2d simulation library and is used in game development. Apart from C/C++ it has ports for various languages like python, javascript etc. With the availability of the html5 canvas element and many other html5 apis, it becomes possible to write browser based games in javascript. So in this article we shall try to make a simple racing car kind of element in javascript using the box2d library.
Here we use the Box2d Javascript port from
http://code.google.com/p/box2dweb/
Car
The car shown here has 5 parts :
1. Middle Body
2. 2 Front wheels connected to body using revolute joints.
3. 2 Rear wheels connected to body using prismatic joints with limits
A much more simpler approach would be to take just 1 piece of shape and move it leftward or rightward. But that would not look very 'natural' or realistic as the one with wheels and extra simulation would.
Demo

In terms of physics, to move the car, force is applied on the front wheels in the direction of their rotation angle, means push them in whichever direction they are facing. So when the front wheels move, they take the rest of the car with them making the whole car looks very real.
Code
The...

Read full post here
Make a racing car using Box2d in javascript


Viewing all articles
Browse latest Browse all 8

Trending Articles