I am trying to make a simple flappy bird clone (in order to act as a sort of practise / first game, NOTE: This is not my first game). I am trying to imitate the rotation that occurs whenever you “fly” (as in pointing up, then gradually point downwards). I have tried using smoothdamp and lerp but neither are working… The outcome of what the code is outputting, is that the bird just keeps rotation (z axis) with no stop.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Fly : MonoBehaviour
{
public float flyVelocity;
Rigidbody2D rb;
bool canFly;
Vector3 currentRotation;
public Vector3 targetRotation;
float rotationSpeed = 180f;
float smoothTime = 0.3f;
//Vector3 rotationVel = new Vector3 (0, flyVelocity, 0);
void Update()
{
currentRotation = transform.eulerAngles;
currentRotation.z -= 10f;
if(transform.eulerAngles.z <=-40)
{
currentRotation.z = -40;
}
transform.eulerAngles = currentRotation;
if(Input.GetButtonDown("Jump") && canFly)
{
currentRotation = new Vector3(
0,
0,
Mathf.LerpAngle(currentRotation.z, targetRotation.z, Time.deltaTime));
transform.eulerAngles = currentRotation;
rb.velocity = new Vector2(rb.velocity.x, flyVelocity);
}
}
}