Search Unity

NavMeshAgents doesn't collide with eachother

Discussion in 'Navigation' started by Power07RM, Apr 22, 2015.

  1. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    About the problem:

    I have got a Player that has two scripts attached(PlayerController and Entity), a rigidbody(isKinematic checked, no gravity), NavMeshAgent and SphereCollider.

    Then I have got two exactly the same Enemies that have two scripts attached aswell(EnemyAI,Entity), a rigidbody(same),NavMeshAgent and SphereCollider.

    Now the problem is that, I can go through them and they can go through eachother aswell. And this is something I deffinitely want to get rid of. To Move both enemy and player I simply use agent.destination. I put them also on different layers consequently "enemy" and "player" and marked to detect collision between them. Unfortunately that didn't appear to help.

    And here goes my question. How to solve that? Thanks for your time and suggestions, hopefully they will lead me to the solution.
     
  2. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    I guess it's because isKinematic is set to true, set to false and see if that helps.
     
  3. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    Well it does, but if I uncheck isKinematic I can move my enemy (for example I am at the tunnel and he is standing at the entrance, I can just click to move forward and eventually he will be forced to move and this is something i need to avoid). They should be non-kinematic indeed, but I need something to prevent them pushing eachother.
     
    Last edited: Apr 22, 2015
  4. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Why do you need Rigidbody on them anyway if you are using Navigation?
     
  5. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    Using OnTriggerEnter.
     
  6. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Ok so you all setup sounds a bit confusing now. I can only suggest to use Vector3.Distance instead of OnTriggerEnter. Basically check the distance between the player / other objects and trigger them if distance is less than x.
     
  7. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    I have got a gameObject for enemy with children empty objects that contains box colliders(for attackArea, for chaseArea, for LookAt Area). I want to use navmesh for pathfinding and those triggers for detecting if player has reached any of enemy's area to behave properly for every of those areas. This results in having gameobject for player and enemy that contans rigidbody collider and navmeshagent. Of course I will keep in mind your suggestion about Vector3.Distance and i found it really helpfull as I totally forgot about this. But triggers are faster, aren't they? That's why I'd rather keep this setup but fix the collision detection between actors. If u've got anything more in your mind to help me I am here. Also waiting for someone else to response. Thanks again for your time.
     
  8. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    non-kinematic rigidbody with gravity , drag set to 1 and increased mass did the job. Thanks for help :)
     
  9. thomkoled

    thomkoled

    Joined:
    Oct 28, 2014
    Posts:
    11
    Hey Power07RM,
    I have the same problem... I cant figure it out... Im missing something... Or what.. Could you attach the example source code pls??

    Thank You very much!
     
  10. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    example source code of what? My issue was mostly about setting up the components of both player and enemy and as I said they should be non-kinematic(isKinematic is unchecked - because then the rigidbody can detect the collision), drag - at least in my case - set up for 1(It's causes less impact of forces), useGravity checked ( in my case enemies and player are walking on the ground and this also prevents flaying away when the collision appears) and mass! I set up mass to 100 like they are muscle guys. What I accomplished is that I have 10 enemies(for example) and player trying to go through the crowd and it is slightly possible(but still is), but what's important they are not flaying away and when collision is detected I can no longer see the vibrations(I could've seen them before because my camera position is based on player's transform.