jerome Posted June 5, 2018 Share Posted June 5, 2018 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). GameMonetize, coolroar, Wingnut and 5 others 7 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 5, 2018 Share Posted June 5, 2018 what a beautiful car jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 5, 2018 Author Share Posted June 5, 2018 yep, the best Cx ever (and colors also) NasimiAsl, JohnK and GameMonetize 3 Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted June 5, 2018 Share Posted June 5, 2018 wonderful jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 6, 2018 Author Share Posted June 6, 2018 Updated : http://jerome.bousquie.fr/BJS/test/carSim1.html Now a followCamera follows the car according to its speed (close at low speed, far at high speed) and I added a hand-made centrifugal effect on the chassis so the car can swing left or right when turning at enough speed Quote Link to comment Share on other sites More sharing options...
jerome Posted June 7, 2018 Author Share Posted June 7, 2018 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 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 7, 2018 Author Share Posted June 7, 2018 first quick and dirty buggy attempt to make tracks : http://jerome.bousquie.fr/BJS/test/carSim2.html the dynamic texture is more complex to handle than I expected [EDIT] dynamic texture / ground ratio fixed... now investigating about the drifting tire tracks Quote Link to comment Share on other sites More sharing options...
renjianfeng Posted June 9, 2018 Share Posted June 9, 2018 I'm not sure if it's because of my network problem, I can't open your website,I really want to see your demo. Quote Link to comment Share on other sites More sharing options...
jerome Posted June 9, 2018 Author Share Posted June 9, 2018 It's probably due to some limitation on the firewall protecting my website. I'll check this next monday [EDIT] firewall limitations fixed Quote Link to comment Share on other sites More sharing options...
coolroar Posted June 9, 2018 Share Posted June 9, 2018 Fun ride! ??⚡ ________________/ jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 11, 2018 Author Share Posted June 11, 2018 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 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 12, 2018 Author Share Posted June 12, 2018 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 GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.