- Home /
Question by
frame_th · Apr 25, 2012 at 06:59 AM ·
aienemyairplanelookattarget
AI Airplane Problem
I want to make airplane of enemy. First, the airplane flight to straight if it flight into
area which is near target(in my code: Distance(target,airplane)<50). the airplane have to rotate and move to target(terret) but I have a problem when the airplane bombarded, it should to go away from this area but it is not because it 's not break this loop(Distance(target,airplane)<50)
I am sorry if I use English badly. public override void AIOutOfRange() { target = GameObject.FindWithTag("Tower").transform;
aiDistance=Vector3.Distance(target.position,transform.position);
if(aiDistance< 50 && aiDistance > 20){
Debug.Log("Hey! I see tower!!");
//Rotate to target
Vector3 rotateHorizontal = target.position - transform.position;
//Debug.Log(aiDistance);
rotateHorizontal.y = 1;
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(rotateHorizontal),Time.deltaTime);
//move toward the target
transform.position +=transform.forward*moveSpeed/2*Time.deltaTime;
}
transform.Translate (0, 0, moveSpeed * Time.deltaTime);
Comment
Your answer
Follow this Question
Related Questions
Follower Airplane problem 1 Answer
Bug with my enemyAI 2 Answers
Enemy AI Problem 0 Answers
free roaming enemy ai 1 Answer
Send an enemy back to its spawn point using waypoints 2 Answers