austincap Posted May 10, 2018 Share Posted May 10, 2018 Considering they all have to be called for nearly every sprite, every single frame, what's a good number of collision functions for me to use? I'm making a multiplayer shooter game, but I'd like a more general answer as well. Quote Link to comment Share on other sites More sharing options...
chriswa Posted May 10, 2018 Share Posted May 10, 2018 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? 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.