- Home /
Question by
jordmax12 · Mar 02, 2014 at 04:47 PM ·
c#artificial intelligence
Is this making my AI move?
So I am in a Game AI class and we're learning about FSM's and AI behavior, and I am trying to get my AI to flee away from target (player) but I am having some issues with that. The script I have does make it do some kind of movement, but like it's weird and glitchy. I was wondering if anyone had any experience with this can help me out I would really appreciate it. I can't tell if I am making my AI move in my code, he does move because of code I wrote, but I want him to be fluid and flee away from player.
ublic class FleeScript : MonoBehaviour {
public AIClass a;
public int nextStateClicker;//change to private
public float FleeTime;
public GameObject target;
public Transform targetTrans;
public float maxVel;
// Use this for initialization
void Start ()
{
Debug.Log ("Player has obtained coin, flee mode!");
ChangeStateFlee ();
target = GameObject.Find ("Player");
targetTrans = target.transform;
maxVel = 28;
}
// Update is called once per frame
void Update () {
}
public enum FleeState
{
FSearch,
FFlee,
}
public FleeState fleeState;
IEnumerator FSearchState()
{
fleeState = FleeState.FFlee;
yield return 0;
}
IEnumerator FFleeState()
{
Vector3 distance = targetTrans.position - transform.position;
float updatesAhead = distance.magnitude / maxVel;
Vector3 movePosition = target.transform.position + target.transform.rigidbody.velocity * updatesAhead;
yield return (movePosition);
}
/*IEnumerator FleeTimer()
{
} Set Later */
void ChangeStateFlee()
{
StartCoroutine(FSearchState ());
}
void ChangeStateSearch()
{
StartCoroutine(FFleeState());
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613135156im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to make a seamless transition between movie clips? 2 Answers
C# multiple AI Waypoint tutorial 0 Answers