Search Unity

How to prevent player steps / walks on colliders?

Discussion in 'Physics' started by moco2k, Apr 16, 2016.

  1. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    289
    Hey,

    I have experienced an issue where my player is able to walk on enemies, which I would like to prevent somehow.

    As it regards the setup, the player object has the following components (among others): Character Controller, Rigidbody (kinematic), Nav Mesh Obstacle. Monster objects have Rigidbody (kinematic), Capsule Collider and Nav Mesh Agent.

    I usually set the radius of the Nav Mesh Agent (monsters) and Nav Mesh Obstacle (players) a bit bigger than the radius of the respective colliders. This measure basically works quite well for me to avoid the above issue. However, I have just added a new monster with a horizontal capsule collider (see attached screenshot) for which this solution is not appropriate so I have run into this issue again.

    I was wondering if there might be another solution to this.

    Thanks for your help

    JumpOnCollider.JPG
     
  2. Harley-B

    Harley-B

    Joined:
    Aug 12, 2013
    Posts:
    3
    If you go to edit > project setting > physics you can set which layers interact with each other. You can set layers on the individual game objects in the top right of the inspector. If you are not using layers currently you can get a fair bump in performance by having everything not check everything else. However, if nothing else, you can use a non-uniform box collider pointing up like a Christmas tree (or build a simple mesh collider with similar properties (although that will be more expensive) that is steep enough that it will just cause the character to slide off. With the layer though you can set up your own that you can detect against it (with a raycast, or a physics collision) and then trigger a falling animation or add force etc to move the player off. Good luck.
     
    bowserscastle likes this.
  3. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    289
    I think layers are not a problem here; they all seem to be set up alright.
    I have also already tried to use really big colliders for which it would be definitely impossible to jump on (see screenshot). While this solution seems to work well for static stuff, it does not prevent my players from being able to walk on monsters with Nav Mesh Agents...

    JumpOnCollider2.JPG
     
  4. metamorphist

    metamorphist

    Joined:
    Mar 15, 2014
    Posts:
    77
    Try reducing the slopes. often times skinned mesh renderer is counted as slopes and so are several charactercollider
     
  5. Unimersiv

    Unimersiv

    Joined:
    Sep 29, 2016
    Posts:
    2
    I have the exact same issue, did you manage to fix it? The player is controlled with a CharacterController, I set the slope limit to 0 and the step offset to 0 too, but when it gets really close from a NavMeshAgent it goes on top of it and continue to walk on his head like in the image on top.

    Anyway to fix this?
     
  6. ChadrickEvans

    ChadrickEvans

    Joined:
    Mar 14, 2015
    Posts:
    38
    Anyone that comes across this, I just fixed it by changing the height of the navMeshAgent itself. Not sure why that's an issue.
     
unityunity