Hello, I am quite new to Unity, and I was wondering how to (in C# preferably) accomplish a simple full 360 degree in all directions rotation through quaternions (space flight simulation style)? Nothing fancy, no limitations, just being able to rotate in all directions, WITHOUT having the “input direction” change, meaning once I’ve passed 180, I don’t want the left and right to swap. So rotation relative to the world is what I’m looking for I THINK… Help is greatly appreciated! Thanks!
EDIT: To be more specific, I need full pitch roll and yaw on ALL 3 axis, the rotations will be added via mouse movement/joystick movement, roll will occur in place of yaw when a button is pressed, and become yaw again when the button is released.
If rotating only around axis Y (horizontal plane) and X (vertical plane), you can detect when the object is upside down and invert the horizontal control direction. If you plan to rotate around Z too, however, the resultant movement may become too weird to understand - it’s better to let Z alone, or use it just to bank in small angles.
void Update(){
// define the horizontal rotation direction:
float dir = 1;
if (transform.up.y < 0) dir = -1; // if upside down, invert horizontal dir
float dt = turnSpeed * Time.deltaTime;
// turn right/left (around Y) according to dir and Mouse X
angles.y = (angles.y + dir * Input.GetAxis("Mouse X") * dt) % 360;
// turn up/down according to Mouse Y
angles.x = (angles.x - Input.GetAxis("Mouse Y") * dt) % 360;
// assign new angles to eulerAngles (or localEulerAngles)
transform.eulerAngles = angles;
}
These look good, but I need rotation on ALL 3 axis. It’s for a space-flight sim. type project, so turning is ALWAYS relative to the player. Thanks for the help so far!