@Touchyyyx try it like this and add an onCollisionEnter to set hitGround true to stop the motion.
using UnityEngine;
using System.Collections;
public class BirdMovement : MonoBehaviour
{
Vector3 velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 flapVelocity;
public float maxSpeed = 5f;
public float forwardSpeed = 1;
bool didFlap = false;
public bool hitGround = false;
void Start ()
{
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
{
didFlap = true;
}
}
void Flap()
{
velocity += gravity * Time.deltaTime;
velocity.x += forwardSpeed;
if (didFlap)
{
didFlap = false;
if (velocity.y < 0)
{
velocity.y = 0;
}
velocity += flapVelocity;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
}
void CheckAngle()
{
float angle = 0;
if (velocity.y < 0)
{
angle = Mathf.Lerp(0, -90, -velocity.y / maxSpeed);
}
transform.rotation = Quaternion.Euler(0, 0, angle);
}
void FixedUpdate()
{
CheckAngle();
if (hitGround == false)
{
Flap();
}
}