Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Some questions about collisions  (Read 1393 times)

0 Members and 1 Guest are viewing this topic.

mattr

  • Newbie
  • *
  • Posts: 13
    • View Profile
Some questions about collisions
« on: July 13, 2013, 08:39:06 pm »
I have a vague idea of how collisions might work, but I want to run it by someone who actually knows what they are doing before I waste a lot of time.

Imagine I'm making a space invaders type game. Important collisions would include:
  • Player bullets hitting invaders
  • Invader bullets hitting the player
  • Invader bullets hitting the barriers
  • Invaders hitting the barriers

So there are going to be numerous bullets flying at once, and any of them may collide in any of the ways I've just described. So at every step in the event loop I would have to keep track of (possibly in a vector):

  • every bullet
  • every invader
  • every barrier
  • the player

And at every step I would have to check if any of the entities I am keeping track of has collided with any of the other ones. This seems like it could get out of hand really fast. That's a lot of calculations to have to do at any given moment, and it would seem a lot better if I could just write callback functions that would run if any of the collision scenarios occured. Is there another way to do this that I'm not seeing?

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Some questions about collisions
« Reply #1 on: July 13, 2013, 08:56:49 pm »
That's pretty much it.  Remember, with these new fangled machines called computers large numbers of calculations are a breeze!  no seriously, for a space invaders type game checking the player against all other enemies and checking each bullet against all enemies should give you no performance issues at all.  When you do get into bigger scopes then to optimize your collision checks you gotta get into some kinda spatial partitioning tree like BSP trees, quad trees and the like.  But even those are still doing all the same checks, its just the tree structures usually make it so the top couple levels are all the entities closest to the object you're checking agaisnt, so instead of iterating through a list of all enemies for a bullet collision, you are only checking against a handfull of closest enemies, and at whatever timesteps or intervals you feel work for you scope you update the tree to reflect the closest entities to your bullet/player at the current timestep.

Sorry if that seems a bit confusing but i only got a moment to write this out.

Basically you know what you gotta do and shouldn't worry about how many checks you are doing until you start to see a performance drop.

mattr

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Some questions about collisions
« Reply #2 on: July 13, 2013, 10:24:58 pm »
Ok thanks a lot. I guess it just seems really inefficient. I mean, I parse log files with regexes at work that are millions of lines long, and that goes pretty fast (and that's in python!), so I guess this just seemed like a lot more work because the steps are more varied.

 

anything