Search Unity

Question Trying to figure out how to apply force to a nav agent

Discussion in 'Navigation' started by Badparrot, Feb 13, 2024.

  1. Badparrot

    Badparrot

    Joined:
    Mar 30, 2022
    Posts:
    1
    Code (CSharp):
    1. IEnumerator GetKnockBacked()
    2.     {
    3.      
    4.         yield return null;
    5.         _agent.enabled = false;
    6.         _rigidbody.useGravity = true;
    7.         _rigidbody.isKinematic = false;
    8.         //add somehow detect getting kicked by player
    9.         yield return new WaitForFixedUpdate();
    10.  
    11.         yield return new WaitForSeconds(0.5f);
    12.  
    13.         _rigidbody.velocity = Vector3.zero;
    14.         _rigidbody.angularVelocity = Vector3.zero;
    15.         _rigidbody.useGravity = true;
    16.         _rigidbody.isKinematic = true;
    17.         _agent.Warp(transform.position);
    18.         _agent.enabled = true;
    19.  
    20.  
    21.        
    22.     }
    Hey folks, uber noob here, been wondering how to get my Nav agent to be able to get pushed (this is for the player's kick) and wondering how I would get a detection through, kick is a hot box but i also have traps that have them to, but I don't want the AI to turn off on a trap over and over again.
     
  2. Hermetes

    Hermetes

    Joined:
    Jan 6, 2016
    Posts:
    12
    Hi, first that i see is you call agent.Warp on disabled state.