- Home /
Another question about the flying enemy
I want to make an enemy that can fly and I didn't find ani tutorials about it... I already made the enemy take off like helicopter, now this is my problem: after it taking off the land it need to follow me but when it not change his y axis (like it follow me in the air) but it coming to my plase.
How I make it follow me without it will change his y axis and it will not "look" at me?
That what i did 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); }
Sorry for poor english.
Answer by poncho · Feb 22, 2011 at 06:36 PM
for the following you can try
transform.position = new Vector3( Vector3.Lerp(transform.position, target.position,Time.deltaTime).x, transform.position.y, transform.position.z);
this will only get to make the transform close to you on x axis, cuz you kept the y and z values dont copy paste it, cus its on C#, just try to make it on js
I don't know how to make it on JavaScript... I tryed...
Your answer
Follow this Question
Related Questions
AI Enemy Follow Player 2 Answers
Enemy Follow Disable Y Axis 1 Answer
Camera rotation around player while following. 6 Answers
Enemy not rotating when inside range 1 Answer
Change AI Follow Players 1 Answer