Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cant seem to get 2D collisions to work?

Discussion in '2D' started by aronomalley, Nov 8, 2018.

  1. aronomalley

    aronomalley

    Joined:
    Nov 7, 2018
    Posts:
    3
    I am currently making an android 2D game with unity. I have everything down like the players movement, jumping and basic level design but for some strange reason for the life of me I cant get collision detection to work with my player character. To put it more simply, I have set up code in the script for when the player collides with a "Spike" sprite a message will be displayed to the debug window that simply says "Collided!". The script is put inside of my player sprite.

    Code (CSharp):
    1. private void onCollisionEnter2D(Collision2D collision)
    2.     {
    3.         if (collision.gameObject.tag.Equals ("spikes"))
    4.         {
    5.         Debug.Log("Collieded!");
    6.         }
    7.     }
    just for testing purposes to try and see what the exact problem is. But no matter how many times I make the player character hit into the spikes at full force I will not receive the message to the console log. If anyone has any suggestions I would be extremely grateful. Anymore code that needs to be provided please ask because I need this problem solved asap.
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    OnCollisionEnter2D
     
    aronomalley likes this.
  3. aronomalley

    aronomalley

    Joined:
    Nov 7, 2018
    Posts:
    3
    Holy hell.

    Dude I'm such a dummy thank you, wish I saw this 2 hours earlier
     
  4. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Here in the forum this is the most common error for the not working collision. And at the beginn my scripts didn't worked too because of this :D