#Quaternion math is really hard please help

1 messages · Page 1 of 1 (latest)

hearty pivot
#

I'm trying to make aircraft style controls where if you roll and then pitch than the new pitch is based on current roll of the aircraft. Same for when you pitch than roll.

            if (Cursor.lockState != CursorLockMode.Locked) return;

            float mx = Input.GetAxis("Mouse X") * sensitivity;
            float my = Input.GetAxis("Mouse Y") * sensitivity;

            if (inWater)
            {
                _pitch -= my;
                _roll += mx * rollSpeed * Time.fixedDeltaTime;

                // Aircraft-style controls
                if (_cameraRoot)
                {
                    Quaternion rollQuat = Quaternion.Euler(0f, 0f, _roll);
                    Quaternion pitchQuat = Quaternion.Euler(_pitch, 0f, 0f);
            
                    _cameraRoot.localRotation = rollQuat * pitchQuat;
                }
            }

This is my look function while swimming. I have asked so many ai chat bots about this but none of them gets it right.

unkempt root
hearty pivot
#

I'll just paste the explanation I gave to chatgpt. Sorry if its bad its really hard to explain for me.

Think about the movement of a plane. If it rolls 90 degrees to the left for example, and then pitches up the new 'up' will be left. Same for if it pitches up and then rolls. The new roll will be associated with the new pitch. The best way to visualize this is the plane.

https://www.youtube.com/watch?v=pQ24NtnaLl8

Simple animation explaining basic aerocraft movement.

Proste wyjaśnienie sterowania samolotem. Polskie terminy zaczerpnięte z wikipedi.

Czy tylko mnie wydają się one dziwne?

▶ Play video
ancient pike
#

What is the actual problem you are having? Changing the local rotation should work

hearty pivot
ancient pike
#

oh this is a child object?

#

Is the parent root object moving as well?

winged plover
#

I would think local rotation is all you need. Moving the mouse up the y axis should always tilt the plane's nose such that you take the transform.forward and tilt it locally upwards

#

Though, I've not played any airplane games for a while

#

Rather, y axis correlate to the local x rotation, but I don't feel like that changes depending on the camera or plane orientation from what I can recall.

#
Quaternion roll = Quaternion.AngleAxis(_roll, Vector3.forward);
Quaternion pitch = Quaternion.AngleAxis(_pitch, Vector3.right);
_cameraRoot.localRotation = roll * pitch ;```
This should be the better idea over the euler methods you are using, but I'm kinda confused on the camera root so there's probably more going on here
#

Actually if we're talking local rotation then you'd probably want to use Transform.forward here for the up, but I'd try both

hearty pivot