- Home /
How to make a enemy dodge/sidestep?
Hi all.
I'm making a AI solution that I may put up on the asset store soon, but I need one more part to finish it. For enemy dodging, I have all the needed information (the enemy figures out if it needs to dodge or not based on the information it get's from it's avoidance area), but now I need to know how to actually make it dodge? It uses navmesh, but I want the enemy to move like he's side-stepping, not turning and walking to a position. Here's my code for the dodge state he would be in.
using UnityEngine;
using System.Collections;
public class ArcherDodge : EnemyState{
private NavMeshAgent agent;
private Archer archerRef;
private PhotomManager manager;
public GameObject[] Player;
public float MoveSpeed;
public override void Initialize (){
agent = me.GetComponent<NavMeshAgent> ();
manager = GameObject.Find ("MPHandler").GetComponent<PhotomManager>();
archerRef = me.GetComponent<Archer> ();
Player = manager.AllPlayers;
}
public override bool MeetsConditions (){
return (archerRef.Avoidance.canSee == true);
}
public override void EnterState (){
agent.speed = archerRef.DodgeSpeed;
}
public override void RunLogic (){
agent.SetDestination (new Vector3(0, 0, 0));
}
public override void ExitState (){
agent.speed = archerRef.WalkSpeed;
}
}
For now it goes to 0, as I wanted something their to test if it was working. Now how would I go about him side-stepping instead to his left or right?
Answer by Red Titan Studios · Apr 24, 2014 at 09:08 PM
get the archer's current position and add/subtract some distance to x or z. agent.SetDestination (new Vector3(transform.position.x + 10F, transform.position.y, transform.position.z));
Your answer
Follow this Question
Related Questions
Array out of range 1 Answer
Horde of NavMeshAgents - stops to recalculate path. 4 Answers
Enemy looks for you, when he can't see you 1 Answer
Enemy Color Change Help! 1 Answer
NavMesh flee. Ai flee from player. 4 Answers