Hello! I am trying to script a very simple Ai for my game. This Code is just for moving my Ai in four DIrections which where randomly chosen. So very basic. But when I try this script on a gameobject in Unity it just flows away and ist not working at all. I set many times that the Y Position cant be changed but the script gives a S***. I dont know what do to any more so I would apreciate some help. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Ai : MonoBehaviour { float direction; float positionx; float positiony; float positionz; public float timeLeft = 4.0f; Vector3 moveDirection; public Transform enemy; void Start() { direction = Random.value; } void Update() { timeLeft -= Time.deltaTime; CharacterController controller = GetComponent<CharacterController>(); positionx = (enemy.transform.position.x); positiony = (2.77f); positionz = (enemy.transform.position.z); if(direction < 0.25f) { while(timeLeft > 0) { transform.Rotate(0, 180, 0); moveDirection = new Vector3(positionx, 2.77f, 0.25f); controller.Move(moveDirection * Time.deltaTime); break; } if (timeLeft < 0) { direction = Random.value; timeLeft = 4.0f; } } if(direction > 0.25f && direction < 0.5f) { while(timeLeft > 0) { transform.Rotate(0, 90, 0); moveDirection = new Vector3(0.25f, 2.77f, positionz); controller.Move(moveDirection * Time.deltaTime); break; } if (timeLeft < 0) { direction = Random.value; timeLeft = 4.0f; } } if(direction > 0.5f && direction < 0.75f) { while(timeLeft > 0) { transform.Rotate(0, 270, 0); moveDirection = -new Vector3(0.25f, 2.77f, positionz); controller.Move(moveDirection * Time.deltaTime); break; } if (timeLeft < 0) { direction = Random.value; timeLeft = 4.0f; } } if(direction > 0.75f && direction < 1.1f) { while(timeLeft > 0) { transform.Rotate(0, 360, 0); moveDirection = -new Vector3(positionx, 2.77f, 0.25f); controller.Move(moveDirection * Time.deltaTime); break; } if (timeLeft < 0) { direction = Random.value; timeLeft = 4.0f; } } } }