Search code examples
unity-game-engine2dcollision-detectioncollision

Unity 2D physics is not colliding when player moves fast


A 2D circle shaped player has the following code

Vector2 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = target;

which sets the player's position to the mouse position, and when it collides with enemies they get destroyed (simple concept).

The problem is that the enemies do not recognize collision when player passes through them quickly so they are not destroyed. This problem frustrated me I don't know why collision doesn't work when an object passes through another object quickly .

Is there a solution? Or it is just UnityEngine Maximum Performance

Thanks in advance.


Solution

  • I recommend you to see this link. It explains much about Collision in unity.It looks similar to your game also.

    1. You could also calculate distance between two objects and when the distance is equal to zero you may destroy that object too.

    Note1: this destroys the object only when it is coinciding with another object.

    1. Or by calculating the outer distance between two objects when it is equal to zero you destroy that object.

    Note2: this destroys the object when two objects are starting to collide.