Jump to content

Best way of detailed collisions


Jefta
 Share

Recommended Posts

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...

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

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...