Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Collision Detection fails/not detected?

Discussion in 'Scripting' started by Zarkopafilis, Apr 25, 2014.

  1. Zarkopafilis

    Zarkopafilis

    Joined:
    Apr 25, 2014
    Posts:
    4
    I followed this tutorial (http://unity3d.com/learn/tutorials/modules/beginner/physics/on-collision-enter)

    And here is how my project looks like.(Its the FPC - player and 2 cubes. 1 for the ground and one named "qBlock")
    I want to destroy the qBlock as soon as the player collides with it(i.e. jumping ontop , on bottom etc)
    Code attached to the player:
    Code (csharp):
    1. #pragma strict
    2.  
    3. function OnCollisionEnter(collision : Collision) {
    4.         if(collision.gameObject.name == "qBlock"){
    5.        
    6.         Destroy(collision.gameObject);
    7.        
    8.         }
    9.     }
    And this will help too:
    (I have not messed around with any physics settings...)

    Try http://i.imgur.com/PHE0954.png
     

    Attached Files:

  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
  3. Zarkopafilis

    Zarkopafilis

    Joined:
    Apr 25, 2014
    Posts:
    4
    Last edited: Apr 26, 2014
  4. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    All I can say is what I'd do if I was you.

    Write a 'Debug.Log("ITS COLLIDING"); outside the if statement in the OnCollisionEnter function.

    Check the 'Console'. If it's not calling the function then you know that the physics is not working. If so check the player has a rigid body and box collider attached as well.
     
  5. Zarkopafilis

    Zarkopafilis

    Joined:
    Apr 25, 2014
    Posts:
    4
    The capsule collider needed to be a little bit bigger, its not needed to ahve a rigidbody on the player side and you need to set the collision detection on the qBlock to be continuous