- Home /
how to change flight direction in a Bird sim
Hi, i new to physics in unity, and i kinda dove into something that might be a bit tricky to implement.
i want to make a player controlled bird, that's able to "flap" in order to push itself forward and up, and also be able to bank left/right to turn.
I've managed to do that so far, but i have an issue that it's very unrealistic. meaning: the bird flies forward, then i turn the Y-axis to turn to the side, but i keep flying in my previous direction.
i understand why this happens, but i want to be able to make a smooth turn / smooth change of direction.
so far i've done this:
private void FixedUpdate()
{
if (Input.GetButtonUp("Flap"))
{
rb.AddForce(transform.up * 20, ForceMode.Impulse);
rb.AddForce(transform.forward * Thrust, ForceMode.Impulse);
}
else if (Input.GetButton("Flap"))
{
rb.AddForce(transform.up * 85);
}
AddRotation();
}
private void AddRotation()
{
Quaternion AddRot = Quaternion.identity;
float roll = 0;
float pitch = 0;
float yaw = 0;
roll = Input.GetAxis("Roll") * (Time.fixedDeltaTime * RotationSpeed);
pitch = Input.GetAxis("Pitch") * (Time.fixedDeltaTime * RotationSpeed);
yaw = Input.GetAxis("Yaw") * (Time.fixedDeltaTime * RotationSpeed);
AddRot.eulerAngles = new Vector3(-pitch, yaw, -roll);
rb.rotation *= AddRot;
}
So far I've tried playing around with Drag, but that will just make my bird stop still in the air. I've tried changing velocity, but then it will just move in the air like a plane.
If i look at a game like this: http://www.unity3dgames.net/fly-like-a-bird-3_play.html I can see the bird changing it's momentum immediately while turning
Answer by Dave-Hampson · May 04, 2015 at 08:07 AM
Maybe you could apply a "lift" Force perpendicular to the wings, so that when the wings turn the force pushes/rotates in that direction too.
Kind of like your "flap" force but running all the time, and balanced against gravity.