Plane controls.

I have been working on this dang problem trying everything I can find and just cannot seem to get just the right mix of code I guess.

What seems to be the biggest issue is when I tilt the plane left or right so the wings are no longer horizontal and then try to tilt forward or backward it doesn’t really act like it should because using Quaternion.Slerp doesn’t use the Space.Self(is my guess).

If your plane is horizontal then you can tilt forward/backward correctly because it sees the rotation the correct way. I am assuming this is probably just something simple im missing.

Here is my code.

if (Input.GetAxis("Vertical") != 0) {
            //Pretty much works
            float tiltAroundX = Input.GetAxis("Vertical") * maxRotation + transform.rotation.x;
            transform.Rotate(new Vector3(tiltAroundX, 0, 0), 10, Space.Self);
        }

        float tiltAroundZ = Input.GetAxis("Horizontal") * maxRotation;
        Quaternion target = Quaternion.Euler(0, 0, tiltAroundZ);
        transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * rotationDamping);

This works for the most part but its not smooth like it would be if I was somehow able to use Slerp.

If you change it up to something like this

float tiltAroundX = Input.GetAxis("Vertical") * maxRotation;
        float tiltAroundZ = Input.GetAxis("Horizontal") * maxRotation;
        Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
        transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * rotationDamping);

You can see what I mean by it doesn’t rotate like I would quite expect it.

Anyone have any ideas or pointers?

Thanks!

I do want to add that the transform.Rotate works but once you get to the 90 degree angle(max rotation) it gets kinda jumpy. Then its not very responsive you let go of the keys and its still trying to move for a few seconds. I have tried changing the time from 0 - 1000(just to test) and nothing seems to help it seem more responsive like the tilting left and right.

Wonder if you’ve solved your problem. I’m looking at simple flight controls as well. I’m thinking that Mathf.SmoothDamp might be the way to go for rotation around the z axis instead of Slerp for simulating the normal tilt of a plane as it turns, but I’m not quite sure hot to implement it yet. For turning left and right, I’m using a simple rotation in world space around the y axis. I’m using AddForce for the forward thrust so that the physics is somewhat realistic. As you can tell, I’m just at the beginning of the flight sim process.