I would like to create a script for a flying player that rotates (turns) the player object along the world Y axis, and rolls (banks) the player along the local Z axis.
I am using the Kinect for motion gesture input, so this script would just control turning & banking left. I’ll copy and modify it for the right sided action. I’ve tried many other more complicated “solutions” I found in forums that haven’t worked. This almost works except for this snag.
Issue: Rotation stops at about -100 degrees. It should continue smoothly through 360 degrees. Also note that both the roll and the rotate work correctly individually, if you comment out the either one or the other.
To test this I created this minimal script…
-
Press S to start object rotation
-
Press and hold horizontal inputs to control object roll
private Quaternion newRotation;
void Update () {
float leanAngle = Input.GetAxis("Horizontal") * 20; if(Input.GetKey ("s")){ //Rolls Player newRotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, leanAngle); transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime); //Rotates Player transform.Rotate(-Vector3.up * 2 , Space.World); } }
Code (C#)