Checking the collision versus performance of game...

Imagine a classic game like spaceinvaders…

In this game, we have to check if the fires (bullets) collide with our ship or the enemies ships.

But, we put the OnCollisionEnter in the ships or in the bullets?

Probably, the count of bullets is more than the count of the ships… In other words, we have more bullets than enemies…

I don´t know if this make sense, but what is the best (thinking performance):

  • use collison check in all bullets? or
  • use collision check in ships?

tks

1 Answer

1

I think it will be more efficient to put “OnCollisionEnter” on every ship. That’s because that way you don’t have to make the bullet get information about the object is colliding with to act in consecuence. Every ship has the same code for the “OnCollisionEnter” (that is, reduce live, explode, whatever you want)