15 ms·
Show HN: Simple 2D car physics with JavaScript
- eitland 7y agoThat is totally amazing! Have played it for 5 minutes on my phone now :-)
- samwillis 7y agoLove it. Reminds me of playing with similar car simulations in Flash when I was at school. Now just make it isometric with collision detection and use maps built with this (currently also on the front page): https://news.ycombinator.com/item?id=21923940 https://news.ycombinator.com/item?id=21923940
- pkstn 7y agoFun idea!
- adventured 7y agoIt immediately reminded me of the original Grand Theft Auto, that overhead view.
- pkstn 7y agoYeah! We used to play Slicks ’n Slides a lot for example back in the days..
- lloeki 7y agoSerious vibes of Absolute Drift here, a very zen indie car game.
- pkstn 7y agoHaha, yeah! But this one is open source ;)
- pkstn 7y agoI used to be a flash developer, started in 1999 with Flash 4 ;)
- djmips 7y agoIt's fun! Nice work.
- pkstn 7y agoThanks!
- Spacemolte 7y agoNice, but I do feel like it's missing a set of tracks from the other set of wheels.
- pkstn 7y agoYeah, let’s see how it evolves!
- alexchamberlain 7y agoThis is nice. It would be cool to have an option of rendering the controls under my thumb?
- pkstn 7y agoTrue that, I’ll add those!
- trekhleb 7y agoThe physics is really nice! Played with it for couple of minutes and even managed to drift/draw "2020" trace on the ground :D
- pkstn 7y agoHaha, nice!
- kmjoshi 7y agoThis is very cool and fun! and its only one page of js code!
- jakciewell 7y agoit's pretty cool and fun
- pkstn 7y agoI’ll add multiplayer soon, hope it’s even more fun then!
- minikomi 7y agoHappy new year, everyone https://imgur.com/a/AIxvWUh https://imgur.com/a/AIxvWUh
- wahlis 7y agoWonderful! Please add some sounds for drifting :)
- pkstn 7y agoGreat idea! :P
- ashisrai_ 7y agoDrifting is awesome.
- pkstn 7y agoIt is! :P
- LoSboccacc 7y ago> multiplayer before you venture there I suggest you move the control code outside of the physic code, abstracting car inputs into a throttle, brake, steer structure which is piloted by inputs elsewhere and feed into the physic update tick along with the car state, or it'll make exceptionally hard to build input prediction and lag compensation further on
- pkstn 7y agoYeah, I think that's about what I'm actually working with right now.. Will be live really soon!
- deleted 7y ago[deleted]
- pkstn 7y agoMultiplayer is live now!
- glaberficken 7y agofunny that you give multiplayer to people and they will use any chance they get to display creativity. look at all the pople trying to draw with their tyres!
- smcl 7y agoI spent more time than I care to admit zooming around on this page
- pkstn 7y agoHaha :)
- fjfaase 7y agoHow long would it take to make the whole screen one color (excluding the red car)? And what is the best strategy: driving in circles or fast alternating between gas and brake?
- pkstn 7y agoLet's see :D
- pkstn 7y agoMultiplayer is live now!!! :D
- driver2020 7y agoAt least on Chrome on Android it is now broken for me (previously working fine), as dragging to steer scrolls the page.
- deleted 7y ago[deleted]
- pkstn 7y agoShould work now?
- 40four 7y agoGreat work @pkstn! Works surprisingly well on a touchscreen. Really enjoyed deck of cards as well :)
- pkstn 7y agoThank you! :P
- citrons 7y agoNice!
- pkstn 7y agoThanks! :)
- n-gauge 7y agoGood work! Q: How well would multiplayer work if you used webRTC data sockets instead?
- pkstn 7y agoNot sure, since you’d need multi to multi connection, not only single to single..
- niix 7y agoThis is great and inspiring. Every few months I spin up a socket.io server and attempt to make an RPG. I get about as far as having the character move around the screen and then usually give up :D
- Waterluvian 7y agoI do a lot of making games just for the fun of it. Good advice I heard is that you're making a game _or_ a game engine. Pick which you care about most and focus on that. I found that phaserjs is a good engine but you still have to do a ton of stuff that other engines give for free. Chiefly, the rich game dev UI that Unity, Godot, Unreal, etc. all have. Don't be discouraged by the different languages. Programming is like 15% of game dev and you can easily make a fun first RPG using examples and stack overflow, and get comfy with a new language along the way.
- pkstn 7y agoHere’s socket server source btw: https://github.com/pakastin/car-ws https://github.com/pakastin/car-ws
- joemaller1 7y agoProject page: https://github.com/pakastin/car https://github.com/pakastin/car
- mechhacker 7y agoThat's pretty cool! Just fooling around with this made me think about replicating it with an Elixir backend.
- pkstn 7y agoShouldn’t be too hard, current backend is here: https://github.com/pakastin/car-ws https://github.com/pakastin/car-ws :D
- wiz21c 7y agonot 100% related but is there any good information source on the web to learn how to build a good car simulator ? I've looked around and it's not very helpful. Usually I end up with physics courses which always repeating the same things. But not much about about : pneumatic (especially how they influence the overall speed), independent wheel modelling, suspension, mass shift, frame deformation, ... I've checked the source code of torcs but it seems quite simple (although the results are very convincing). My goal was to model a (indoor) kart.
- acomjean 7y agoCars are pretty complex. Sony spends years modeling various ones in its “grand turisimo” game. But simpler games model cars pretty well, I’m assuming with a dozen or so parameters (turning radius, acceleration, tire grip, suspension..) you should get something. The “pako ios car simulation” (not open source), has a bunch of cars you drive around that behave more or less like actual cars.
- vsskanth 7y agoI work as a vehicle simulation engineer for a Motorsports team. What you're looking for is broadly classified as Multibody Dynamics. You can model each part individually and connect them to make a complete simulation. There are two parts to building these types of models: 1. IDE and Language - Modelica, ADAMS, Project Chrono, SimScape etc. There are open source and commercial solutions for this. 2. Libraries - Claytex, Modelon etc. most detailed vehicle models and components are sold separately. These are typically written in Modelica. Some IDEs like MapleSim or Mathworks bundle it in their IDE. You can build your own components from scratch but it takes time. The closest to open source I found is: https://sbel.wisc.edu/2018/07/23/chronovehicle-template-based-grund-vehicle-modeling-and-simulation/ https://sbel.wisc.edu/2018/07/23/chronovehicle-template-base... https://github.com/projectchrono/chrono https://github.com/projectchrono/chrono If you want to learn how to do it properly, you can easily find online versions of this book: https://www.elsevier.com/books/the-multibody-systems-approach-to-vehicle-dynamics/blundell/978-0-08-099425-3 https://www.elsevier.com/books/the-multibody-systems-approac...
- 7y ago
- nkrisc 7y agoI see that it works on mobile but u can not for the life of me figure it what the control scheme is. I just touch the screen and the car and to randomly move.
- mrspeaker 7y agoFiguring it out is part of the fun ;) (But spoiler, it's just about moving relative to where you start touching... press then move up the screen to go straight.)
- marius_k 7y agoI like it how those patterns reveal different screen sizes/resolutions.
- pkstn 7y agoHaha, true :D
- cabaalis 7y agoNetworked spirograph simulator :)
- pkstn 7y agoHaha :D
- tomxor 7y agoI love how instantly hackable this is... clone the repo and serve the directory localy and still connects through websockets, no npm crap in the way. :)
- pkstn 7y agoVanilla magic! :P
- pkstn 7y agoSorry, but I blocked connections outside main domain to keep it clean.. Started to see trains, moving sprites etc :D
- tomxor 7y ago:( ah well, was fun while it lasted. I was the "HN" sprite :P
- pkstn 7y agoLooked fun, I was just worried about game performance and server bandwidth usage.. Both frontend and backend are open source and work straight away without bundling, if you want to fiddle around: https://github.com/pakastin/car https://github.com/pakastin/car https://github.com/pakastin/car-ws https://github.com/pakastin/car-ws Pull requests also welcome! ;)
- tomxor 7y ago> Looked fun, I was just worried about game performance and server bandwidth usage.. Yes, that turned out to be a legitimate concern... later on I saw people go a step further and write entire sentences out of cars... they probably didn't realize but it was effectively DoSing your server and preventing anyone else's socket emits getting through so all you could see is the text. I guess it's a difficult balance if you want to allow playful hacking but don't want to be DoSed. (BTW it's easy to bypass the origin restriction by just injecting code into the browser), perhaps a better restriction would be a max sockets per session or IP, that would still allow some hacking but reduce chance of DoS intentional or not. Anyway I changed tack to try implementing some basic bots in smaller numbers. Was fun to see how people interact with them.
- planetis 7y agoNice, can we get tracks too?
- pkstn 7y agoSounds good! :P