- Home /
Handling collisions (triggers)
Hi! This is my first question, I'm kinda newbie in Unity (though with very solid C#/.NET background). I'm writing a space-shooter strategy game.
The game will be 2.5D in terms that environment will be 3D, but action will be 2D only. Since I have my own physics model for objects in game, I will have to implement collisions myself. What I'm wondering is how to handle A-B, B-A collisions. For instance, I have two asteroids colliding. As an effect of collision I will want to decrease life of both of asteroids (resulting in them breaking to smaller parts eventually) and changing speed vectors (bounce).
Mostly likely both asteroids will be created from the same prefab with the same components. So both of them will receive OnTrigger event in a component, which is responsible for handling collisions. But that will cause all actions to be executed twice and I'd like to avoid that.
I've been thinking of implementing collisions only on "initiator" object, so for instance when rocket collides with ship, the whole implementation of collision would be in the rocket object as an "initiator" of action. However, this wouldn't cover collisions of asteroids, ship/asteroids, ship/ship etc.
How can I overcome the problem with same object collision? Should I implement some kind of collision controller, which would take care of such situations? Some other solution?
You can always do asimple bool to prevent collisions to be executed, for example, more than once every second. Unity have very good tools for collisions. Read APIs and look the oficial tutorials.
Your answer
Follow this Question
Related Questions
Collision detection for low relative velocity, high world velocity rigidbodies 2 Answers
How to call OnTriggerEnter once 5 Answers
Stacking mechanic (Parenting Prefab to another prefab on collision) 2 Answers
Collision vs trigger 1 Answer
Change NavMesh Speed after collision/trigger just for 1 object 1 Answer