Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Cant seem to get 2D collisions to work?

Discussion in '2D' started by aronomalley, Nov 8, 2018 at 7:51 PM.

  1. aronomalley

    aronomalley

    Joined:
    Wednesday
    Posts:
    2
    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:
    868
    OnCollisionEnter2D
     
    aronomalley likes this.
  3. aronomalley

    aronomalley

    Joined:
    Wednesday
    Posts:
    2
    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:
    868
    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