- Home /
navemesh agent knockbacked
When the enemy collides with the player it is knockbacked and the movement bugs. I dont know if its from the navmesh agent or the code but here is the code:
public float DashForce = 10;
public float DashAttackCooldown = 2f;
public float LookRadius = 10f;
public float AttackRadius = 3f;
public Transform playerTransform;
public Rigidbody rb;
Vector3 Player;
Transform target;
NavMeshAgent agent;
void Start()
{
target = PlayerManager.Instance.player.transform;
agent = GetComponent<NavMeshAgent>();
Player = playerTransform.position;
}
void Update()
{
DashAttackCooldown -= Time.deltaTime;
float distance = Vector3.Distance(target.position, transform.position);
if (distance <= LookRadius)
{
agent.SetDestination(target.position);
}
if (distance <= AttackRadius && DashAttackCooldown <= 0f)
{
transform.Translate(Player * DashForce * Time.deltaTime);
DashAttackCooldown = 2f;
}
}
void OnDrawGizmosSelected()
{
//LOOK RADIUS
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, LookRadius);
//ATTACK RADIUS
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position, AttackRadius);
}
Comment
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Root motion handled by script. How to still use root motion with disabled navmesh agent? 0 Answers
Nav Agent Moving Only Forwards And Backwards 0 Answers
Multiple Cars not working 1 Answer
Is it ok to use Linear Drag and/or Mass to make an object immovable? 2 Answers