1
\$\begingroup\$

In an RTS if a projectile hits a unit. Who should handle the collision?

If projectile handles the collision, it must be aware of all possible types of units, to know what damage to inflict. For example a bullet will likely kill a human, but it will do nothing to a tank.

The same goes if unit handles a collision. So either way one of them should be aware of all possible types of the other.

Of course the 'true' way would be to do full physics simulation, but that's not an option for an RTS with 1000s of units and projectiles...

So what are the common practicies in this regards?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ The collision handler should handle the collision. It's aware of all the entities. \$\endgroup\$
    – House
    Commented Nov 16, 2012 at 15:14
  • 1
    \$\begingroup\$ personally I make everyone respond. like if you drop a bomb on a building. The bomb should respond by exploding and the building should respond by taking damage. \$\endgroup\$ Commented Nov 16, 2012 at 23:49

1 Answer 1

3
\$\begingroup\$

This is a question that is highly specific to the game and implementation. So let's discuss yours:

But broadly, you don't have to worry about who should handle the collision if both parts of the collision can collaborate on the processing.

For instance, instead of considering all possible damage sources vs. all possible types of units, consider storing only 2 values in the projectile: "Damage Type" and "Raw Damage". Then, when a unit collides with the bullet, have the bullet pass the "Damage Type" and "Raw Damage" parameters.

The Unit then would have some method to calculate how much damage it should take given those two inputs. You'd need to use Delegates, Callbacks, or something similar to communicate between the two objects (you did not list a language, so I can't provide more specifics)

This way, units only have to consider possibilities that are relevant to them, and the bullet doesn't care what it hits.

In this example, Damage Type might be "Projectile", "Explosion", or even something more specific, like "LightMachineGunBullet". Units would then modify the raw damage based on the damage type, for instance, a tank that takes only 10% damage from Projectiles, but 100% from explosions.

\$\endgroup\$
1
  • \$\begingroup\$ +1 But I just wanted to mention that the collision manager handles the actual detection, and notifies each object about the event ( so each can decide what to do with the information ). \$\endgroup\$
    – rootlocus
    Commented Nov 16, 2012 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .