I have a bird model with an animation of its wings flapping. It’s an “in place” animation. I’m trying to make the bird fly forward while moving up and down a little bit. I can get it to move forward and up, but it won’t go down. It seems to get stuck in between the rise and fall functions and just flies straight. Here’s my code:
using UnityEngine;
using System.Collections;
public class bird_fly : MonoBehaviour {
void Update () {
Go();
}
void Go(){
Vector3 newPosition = transform.position;
newPosition.z += 1 * Time.deltaTime;
transform.position = newPosition;
Rise();
}
void Rise(){
Vector3 newPosition = transform.position;
newPosition.y += 1 * Time.deltaTime;
transform.position = newPosition;
if (newPosition.y > 3) {
Fall();
}
}
void Fall(){
Vector3 newPosition = transform.position;
newPosition.y -= 1 * Time.deltaTime;
transform.position = newPosition;
if (newPosition.y < 1) {
Rise ();
}
}
}