1
votes

Hi I have question for which I haven't been able to find an answer thus far. I have two game objects next to each other and each one has a collider. Now when a third object collides with one of the game objects then the direction/bounce of that third object takes a different direction based on which gameObject/collider it touched. This works fine for most part when the gameObjects are hit cleanly but when it collides in the middle of both colliders then it takes a direction in the middle, this causes a problem for my game.

I wanted to know how to make sure that only one collider/collision is triggered (doesn't matter which one) when any other objects collides with both i.e. when it hits the join of both gameObjects.

1

1 Answers

4
votes

Collision happens at the beginning of the frame so you can detect the collision and reset in the LateUpdate:

private bool hasCollided = false;
void OnCollisionEnter(Collision col)
{
    if(this.hasCollided == true){ return; }
    this.hasCollided = true;
}
void LateUpdate()
{
    this.hasCollided = false;
}