Im trying to get it so my game object lands on the ground of my scene, im using a var target2 to get the object to point 0 0 0 on my level, the problem is when i invoke this function, the game object continues to fly forward from its current position, any ideas?
function MoveLand() {
target2 = Vector3(0,0,0);
shouldLand= true;
shouldMoveAir = false;
while(shouldLand)
{
Debug.Log("Move Land");
//rotate
var rotation = Quaternion.LookRotation(target2);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2);
//move
transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime;
yield;
if (transform.position.magnitude <1.1){
animation.Stop("fly");
animation.CrossFade("walk");
// shouldMoveLand = true;
Debug.Log("close to landing");
} }}