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

BoxCollider2D Not Detecting Trigger with Diagonal Movement

Discussion in 'Physics' started by AnthonySturdy, Feb 28, 2015.

  1. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    So I have 3 small BoxCollider2D's attached to my Player which detects what tile the Player is colliding with, and I have it so only 1 of them is enable depending on which way you look (1 Collider for vertical, 1 for East, 1 for West). But when you walk diagonally, I'm guessing it's enabling and disabling the colliders so fast that it can't detect them, which leads to all sorts of problems (Such as being able to walk on water).
    Are there any other ways of just moving the colliders instead of having to enable and disable colliders? I really would like to keep the diagonal movement too, it feels too limited just having single X and Y movement.
    Thanks, Anthony :)
     
  2. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I think dynamic colliders (anything that moves) need non-kinematic rigidbodies.
     
  3. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    I'm not using a Kinematic Rigidbody2D :p
     
  4. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Great, are you using a non-kinematic rb?
     
  5. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    Yeah, IsKinematic is unchecked.
     
  6. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    That's very strange. If triggers still aren't being detected, then it might be a problem with Unity's collision detection and you should support a bug report. Before you do that, double check these things:
    • Objects are on layers that collide with each other
    • Objects aren't passing through each other within the period of 1 fixed timestep
    • Colliders have IsTrigger checked
     
  7. AnthonySturdy

    AnthonySturdy

    Joined:
    Feb 24, 2014
    Posts:
    55
    Yeah, I'm pretty sure it's because if you walk (for example) forwards and left, its activating and de-activating the vertical collider then the left collider, so it doesn't have time for the OnTriggerStay2D to register.
    Not sure if OnTriggerEnter2D would help but then I wouldnt be able to stay still and 'break' blocks.