Hi again.
im fighting with rotations in objects local space and anything i try dont want to work. for a while i thought i understand the logic but it seems i was wrong.
here is a sample code:
using UnityEngine;
using System.Collections;
public class ShipMouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
float rotationX = 0F;
float rotationY = 0F;
void Update ()
{
if (axes == RotationAxes.MouseXAndY && !Input.GetKey (KeyCode.LeftControl)){
/*
rotationX += Input.GetAxis ("Mouse X") * sensitivityX;
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
*/
/*
rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX;
rotationY = transform.localEulerAngles.x + Input.GetAxis ("Mouse Y") * sensitivityY;
transform.localEulerAngles = new Vector3 (rotationY, rotationX, 0);
*/
/*
transform.RotateAround(transform.position, transform.TransformDirection(transform.up),
Input.GetAxis ("Mouse X") * sensitivityX * Time.deltaTime);
transform.RotateAround(transform.position, transform.TransformDirection(transform.right),
Input.GetAxis ("Mouse Y") * sensitivityY * Time.deltaTime);
*/
/*
transform.Rotate(transform.up, Input.GetAxis ("Mouse X")
* sensitivityX * Time.deltaTime, Space.Self);
transform.Rotate(transform.right, Input.GetAxis ("Mouse Y")
* sensitivityY * Time.deltaTime, Space.Self);
*/
/*
rotationX += Input.GetAxis ("Mouse X") * sensitivityX;
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
transform.localRotation = Quaternion.Euler(rotationY, rotationX, 0);
*/
/*
rotationX += Input.GetAxis ("Mouse X") * sensitivityX;
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
transform.localRotation = Quaternion.identity
* Quaternion.Euler(0, rotationX, 0)
* Quaternion.Euler(rotationY, 0, 0);
*/
}
if(Input.GetKeyUp (KeyCode.LeftControl)) {
Screen.lockCursor = true;
Screen.showCursor = false;
} else if (Input.GetKeyDown (KeyCode.LeftControl)) {
Screen.lockCursor = false;
Screen.showCursor = true;
}
}
void Start ()
{
}
}
there are a couple of “tries” as you can see and none of them works.
problem with “rotate” and “rotatearound” is that the object has SOME rotation around Z axis too, I cant understand why
every try with eulerangles failed as when the object look stright up, it rotates the object around world Y instead of local Y
I start to give it up… help pls