When trying to rotate the camera, the position of the player is getting the wrong value, no idea why. As illustrated in this picture the Y position says 226 while the Debug says 18:
Very odd and annoying bug, here is my code:
using UnityEngine;
using System.Collections;
public class MouseLookController : MonoBehaviour {
public float lookSensitivity = 5.0f;
public float smoothDamp = 0.1f;
public GameObject playerModel;
public float yRotation;
public float xRotation;
public float currentYRotation;
public float currentXRotation;
public float yRotationV;
public float xRotationV;
void Start () {
if(rigidbody)
rigidbody.freezeRotation = true;
// Screen.lockCursor = true;
}
void FixedUpdate () {
float playerRotationX = playerModel.transform.localRotation.x * 20;
float playerRotationY = playerModel.transform.localRotation.y * 20;
Debug.Log(playerRotationY);
yRotation += Input.GetAxis ("Mouse X") * lookSensitivity * Time.deltaTime;
xRotation -= Input.GetAxis ("Mouse Y") * lookSensitivity * Time.deltaTime;
// xRotation = Mathf.Clamp (xRotation, -80 - playerRotationX, 80 + playerRotationX);
// yRotation = Mathf.Clamp (yRotation, -50 - playerRotationY, 50 + playerRotationY);
currentXRotation = Mathf.SmoothDamp (currentXRotation + playerRotationX, xRotation ,ref xRotationV, smoothDamp);
currentYRotation = Mathf.SmoothDamp (currentYRotation + playerRotationY, yRotation ,ref yRotationV, smoothDamp);
Camera.main.transform.rotation = Quaternion.Euler (currentXRotation + playerRotationX, currentYRotation + playerRotationY, 0.0f);
}
}
With the
float playerRotationX = playerModel.transform.localRotation.x * 20;
float playerRotationY = playerModel.transform.localRotation.y * 20;
I have it * 20 because otherwise it’s going to be about 0.9 or so, thus not visible moving really. I have no idea what is causing this breaking bug, and it’s very annoying. If you could help me, that would be appreciated!