I am working on a game using GoogleVR, but I don't think that has anything to do with my problem.
Basically, I am testing to see if I can move a stick by using the mouse at the moment.
I am getting mouse movement, as seen from the value of md
:
(-0.5,-1.25)
UnityEngine.Debug:Log(Object)
PlayerMovement:Update() (at Assets/Character Pack/PlayerMovement.cs:30)
But the transform is wrong, as seen from the localRotation
:
(0,0,0)
UnityEngine.Debug:Log(Object)
PlayerMovement:Update() (at Assets/Character Pack/PlayerMovement.cs:29)
I just want to see my stick move in some predictable way based on the movement of the mouse, and I am not certain why my equation is wrong.
public class PlayerMovement : MonoBehaviour {
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
public GameObject stick;
// Use this for initialization
void Start () {
smoothV.x = 0.5f;
smoothV.y = 0.5f;
}
// Update is called once per frame
void Update () {
var md = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
stick.transform.localRotation = Quaternion.AngleAxis (-mouseLook.y, Vector3.right);
stick.transform.localRotation = Quaternion.AngleAxis (mouseLook.x, stick.transform.up);
Debug.Log ("(" + stick.transform.localRotation.x + "," + stick.transform.localRotation.y + "," + stick.transform.localRotation.z + ")");
Debug.Log ("(" + md.x + "," + md.y + ")");
}
}