# helicopter moveing

This is like the third time I asking it, I got answers but they are not helpful... I will ask it diffrent this time: I want to make an enemy that can fly like a helicopter, it takes off normaly (fly up) but it fly to me and not above me like it should. How to make it fly above me and ignore the y axis? I know where is my mistakes but I don't know how to fix theme...

here is my script so far:

``````var targetDistance;
var landDistance;
var target : Transform;
var land : Transform;
var inAirRange = 100.0;
var moveSpeed = 12.0;
var damping = 6.0;
private var isItAttacking = false;

function Update ()
{
landDistance = Vector3.Distance(land.position, transform.position);

if (landDistance <= inAirRange)
{
fly ();
}

else
{
stopFly ();
}

if(isItAttacking)
{
attack ();
}
}

function fly ()
{
isItAttacking = false;
renderer.material.color = Color.red;
transform.Translate(Vector3.up * moveSpeed *Time.deltaTime);
}

function stopFly ()
{
isItAttacking = true;
renderer.material.color = Color.black;
}

function attack ()
{
targetDistance = Vector3.Distance(target.position, transform.position);
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}

``````

I am not using rigidbodies or character controllers.

sorry for poor english.

Looks reasonable enough up until the last line

Try change the attack function to something like this:

``````function attack ()
{
targetDistance = Vector3.Distance(target.position, transform.position);
var offsetDirection = target.position - transform.position;
offsetDirection.y = 0;
var rotation = Quaternion.LookRotation(offsetDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
transform.Translate(offsetDirection.normalized * moveSpeed *Time.deltaTime, Space.World);
}

``````

This will still point the helicopter at the player, but won't move it in the same direction, which may look a little weird, but worth trying

(not an answer, just a recommendation)

If you are developing a helicopter game this might be interesting for you: Unity3D Helicopter Tutorial