Search code examples
unity-game-enginegame-physics

How to have collision detection without physics in Unity?


I am making a simple Unity 2D game. In this there are three gameOjects -
1) The Ground (a long rectangle)
2) The player (a square)
3) The coin (a circle)

Currently i am using colliders on all three. These colliders help the player remain on the Ground and when the player collides with the coin i increment the score.
But the problem is that when the player collides with the coin it behaves as if the coin is a physical object and it stops the player.I dont want this
I want that when the player collides with the coin there is no physical interaction between them

I tried one thing - switching the colliders in player and coin to isTrigger, but in this case the player and the ground interact in the way they should (the player falls through the ground).

What should i do??


Solution

  • Make the interactable objects triggers. That way, you can interract with them, without obstracting your path. To do that, go to the collider Component on the inspector and check the "Is Trigger" checkmark. Then, go to your scripts and instead of the event OnColliderEnter use the event OnTriggerEnter