Alvaro Cavaclanti Posted December 9, 2014 Share Posted December 9, 2014 Hey Guys, My goal is to create a top-down 2d racing game (if the title didn't give it away). I've done a bit of Googling for examples of this mechanic, but haven't found any (yet). On the other hand I've found a lot of "spaceship" mechanics and have been tinkering with it, but couldn't get where I wanted. My intention is to have a minimalist racing mechanic, acceleration/velocity, braking and drag. Oh, and steering. That's the problem, actually. I have used both "velocity/accelerationFromRotation" and modifying the acceleration with Math.cos/sin on rotation. I feel like the issue may be related to reducing the velocity/acceleration while steering (turning left/right), but that didn't work quite well, also. Finally, I'm not asking for dumb copy/paste code per se (but as this may be very basic, I would not dismiss it), instead I would like to know more about the theory, and then try to code it myself. p.s.: If everything goes well I'll write a tutorial and share it. Quote Link to comment Share on other sites More sharing options...
alex_h Posted December 9, 2014 Share Posted December 9, 2014 I've been working on a p2.js game based on this great tutorial: http://www.iforce2d.net/b2dtut/top-down-car it walks you through an approach to steering by applying directional forces to your cars wheels. (Hopefully I will actually find time to finish the damn game one day...) Quote Link to comment Share on other sites More sharing options...
Alvaro Cavaclanti Posted December 9, 2014 Author Share Posted December 9, 2014 I've been working on a p2.js game based on this great tutorial: http://www.iforce2d.net/b2dtut/top-down-car it walks you through an approach to steering by applying directional forces to your cars wheels. (Hopefully I will actually find time to finish the damn game one day...) Nice, Alex! I'll go through it and see what I can make use. I wasn't thinking on using such elaborated physics (separated tires) but that will certainly help. If anybody has more tips, don't be shy. Quote Link to comment Share on other sites More sharing options...
harrywatson Posted December 10, 2014 Share Posted December 10, 2014 Hey! Bingo! This might help, funnily enough I was looking at how to shoot a cannon ball in physics and found this: http://codetheory.in/html5-canvas-and-friction/ He ( Rishab ) has a great website - well explained and examples you can run right there on the page. Well - fancy this! He uses a nice race car physics example on the above page! he also has a solution for a scrolling background .... http://codetheory.in/moving-scrolling-sliding-background-in-html5-canvas/ I'll be watching this site. It's fantastic. (you could always use a simple image rotation for tyres and bind it to key codes). Good luck - I'll go back and see if I can get a cannon ball to arc Quote Link to comment Share on other sites More sharing options...
kiture Posted December 10, 2014 Share Posted December 10, 2014 Hi, Here you can find example in js using box2d: http://domasx2.github.io/gamejs-box2d-car-example/ and here is source code for it: https://github.com/domasx2/gamejs-box2d-car-example harrywatson 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.