Jefta Posted December 12, 2013 Share Posted December 12, 2013 Hi, last time i'm trying to get my head around gaming with HTML5, but i can't really think of a way to do detailed collisions in vanilla Javascript. With detailed i mean (almost) pixel-precice, i absolute don't want objects to get stuck in my games. Does anyone knows a good way to do this?- Jefta Oh and ofcourse i searched on this forums before posting, but surprisingly i didn't find anything about this... Quote Link to comment Share on other sites More sharing options...
Paul Brzeski Posted December 13, 2013 Share Posted December 13, 2013 Jefta kree! Are you talking about 2D or 3D collisions? There are various frameworks out there but it depends on what library you're using to draw with. It also depends on whether you're talking about a server backed environment for a multiplayer game where concurrency is required... I gave PhysiJS a shot once, but had some issues trying to get it running server side. It was easier to just manually calculate certain collisions I was interested in than trying to make a fully dynamic world. Quote Link to comment Share on other sites More sharing options...
Gio Posted December 13, 2013 Share Posted December 13, 2013 If you need almost pixel precise collisions (but not exactly pixel precise), you could look at implementing a SAT-based (Separating Axis Theorem) approach, which works with all convex shapes. For concave shapes, you would have to add some additional logic to represent them as a set of convex shapes. There's a fairly detailed explanation with an AS3 implementation here. It would look very similar if you wanted to do it in javascript. In terms of performance, that particular implementation isn't exactly optimal though, it creates lots of unnecessary objects and there is certainly room for improvement. Also, that deals with collision detection, which is only part of your problem. You want to have good collision resolution too, and that is quite challenging. In fact, if you absolutely don't want objects to get stuck or behave incorrectly, and objects can be any shape, then this is a really tricky problem. There's a nice (but complex) paper about it here. Quote Link to comment Share on other sites More sharing options...
Jefta Posted December 14, 2013 Author Share Posted December 14, 2013 @Paul, I'm talking about 2D collisions, but what does Jefta kree mean?@Gio, Thank you for the links. I think i'll go with the SAT-thing for now. 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.