Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
The collision handler should handle the collision. It's aware of all the entities. –  Byte56 Nov 16 '12 at 15:14
1  
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. –  Benjamin Danger Johnson Nov 16 '12 at 23:49

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
+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 ). –  rootlocus Nov 16 '12 at 16:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.