Jump to content

How many collision functions should I use?


austincap
 Share

Recommended Posts

I'm not sure how to answer "how many", but I can suggest that you start with the simplest solution (probably checking every sprite against every other sprite,) then test it on your slowest target platform and optimize only as required. Some optimizations you may consider:

  • do bounding box checks first, before more expensive but accurate collision checks
  • filter collision tests for sprites which have no collision response according to your game logic (e.g. player with player bullets)
  • filter checking stationary sprites with other stationary sprites
  • make sure you're not making redundant checks (e.g. if sprite A collides with sprite B, there's no reason to check if B collides with A)
  • separate physics updates from animation frames so you can run your physics at a slower rate (e.g. 30fps or 20fps) than your rendering frames (blend between physics steps to achieve smooth movement when rendering at a higher framerate) (see https://gafferongames.com/post/fix_your_timestep/)
  • replace pixel-based collision tests with math-based geometric tests, building up a "hit area" for your sprites out of circles, triangles, etc.
  • avoid calculating square roots when figuring out distances if you can deal with the squared values instead (e.g. if you're sorting, sqrt doesn't matter; if you're checking against a circle's radius, square the radius instead)
  • store your bounding boxes in a quadtree to avoid checks between distant objects

Hope this helps?

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