Jump to content

Car Light Physics Engine


jerome
 Share

Recommended Posts

Hi people,

I'm currently investigating about some car games (car races in towns or on circuits or on mountain roads, etc). I know BJS can work great with some nice physics engine like Cannon, Oimo or Energy but I like to have lighter and more dedicated stuff when possible. That's why I took a look at this nice library : https://github.com/spacejack/carphysics2d

There's a live demo here :   http://www.spacejack.ca/projects/carphysics2d/

Use up and down arrow to push the gas throttle or the brake, the left and right arrow to steer the wheels and the space bar to pull the e-brake... drifting is so fun. Well, this is a light 2D library dedicated only to the car physics : you know, all the stuff about mass transfert on the wheel axis, acceleration, frictions, tire gripping, etc, etc. It's really light : the commented and un-compressed part of the code about the physics themselves is about 100 LOC only.

So I just had a quick try to adjust it to work with a BJS example. This is not a real port, not even an adaptation in some BJS-esque style, just a plug to make it work with some 3D objects instead of 2D ones. Of course, I had to add some tiny logic to have 4 wheels rotating according to the current car speed.

Here's a first quick and dirty proto : http://jerome.bousquie.fr/BJS/test/carSim1.html

The car front is blue, the back is red. Up and Down arrow to speed up or to brake. Space bar to pull the e-brake. Just click once in the canvas before because the keyboard controls of the ArcRotateCamera have been disabled in order to be used as car controls instead. Note : the car can't drive backwards ?

This could be proted, refactored in the BJS way and optimized then (added to my todo list).

 

 

Link to comment
Share on other sites

Could my little car handle some relief ?

yes, it can : http://jerome.bousquie.fr/BJS/test/carSim1.html

Note that there's no real physics engine here about the car terrain detection, only the use of the ground normal at the current car location and a global rotation applied to the car according to this ground normal and the car direction vector. So it's not as accurate as a real physics engine at the wheel/ground contact but far more faster. My goal is to make fun or pleasant rather than accurate :)

Link to comment
Share on other sites

Just updated.

Now, the tire track intensity is proportional to the car velocity and its yaw rate. So you'll print tracks only by turning at decent speed or when drifting (turn + e-brake : space bar)

http://jerome.bousquie.fr/BJS/test/carSim2.html

F5 to refresh the browser cache

 

[EDIT]second update to get more independent wheel behavior (quite no wheel digging in the ground any more), still with a fake physics engine

Link to comment
Share on other sites

drive fast in the palm tree forest ... as long as there's no collision detection up now ?    (2500 trees !)

http://jerome.bousquie.fr/BJS/test/carSim2.html

F5 to refresh the browser cache, then click in the window before starting, as usual

 

[EDIT] changed  the palm trees so as they don't look like sprites anymore

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...