I am trying to make a bird game but it doesn’t copy flappy bird at all but I just liked the physics where when the bird goes up the sprite rotates up so it looks upwards and when it falls down the bird rotates downwards. I originally was going to have 3 sprites but it would look very twitchy. So the basic idea in my mind is change the rotation of the plane depending on the velocity of the bird.
float angle = Vector3.Angle(Vector3.right, rigidbody.velocity);
if (rigidbody.velocity.y < 0)
angle = -angle;
transform.eulerAngles = new Vector3(0, 0, angle);
And yeah, this is just one of many ways.) Play with code to suit your needs, for example - try to make it work without “angle = -angle” line. I don’t like it, but it works. )
For reason I changed the script to my setting and put a var angle : float; When I run the game it doesn’t rotate on the z-axis it only rotates around the y-axis for some reason. I went over and over my script but I can’t seem to understand why it would rotate on the y axis.
angle = Vector3.Angle(Vector3.right, rigidbody.velocity);
if (rigidbody.velocity.y < 0) {
angle = -angle;
}
transform.eulerAngles = new Vector3(90, 180, angle);
EDIT : I figured out why it was doing it but I don’t know how to fix it now. For some reason with my plane the rotations change after it goes past the 90*'s and changes the y rotation to 270 from 90 and z rotation from 90 to -90. The rotation is working fine but I just can’t figure out how to fix this rotation issue. I was thinking of putting it on a 3d gameobject like I did the clouds. I haven’t had any problems with that.
You got a Gimbal Lock, look for some videos on YouTube for explanation. Long story short - Euler angles applied to body axis-by-axis, and sometimes one axis compensate another. This is why Quaternions even exists. ) Simple solution will be to parent your object with needed fixed rotation to object with zero rotation, and apply your Z rotation to that “clean” parent object. Or mess with quaternions. ) Or - another way - normalise your models and sprites to Unity coordinate system.
I used this for my project, and it doesn’t do anything, the farthest thing it does is make spiral in circles. Unless I’m missing or writing something wrong? I type it exactly as you show it (in their respective fields of course). Just as a note, my character starts in a -90 z rotation initially because I play a small “animation” before the game begins.