Iv been following etteski FPS tutorials and have had no problems so, but now im suddenly getting Nan errors even tho i only changed a non important thing i added into the script.
this is the ‘mouseLookScript’
var defaultCameraAngle : float = 60;
@HideInInspector
var currentTargetCameraAngle : float = 60;
@HideInInspector
var ratioZoom : float = 1;
@HideInInspector
var ratioZoomV : float;
var clampDown = -70;
var clampUp = 70;
var ratioZoomSpeed : float = 0.2;
var lookSensitivity : float = 5;
@HideInInspector
var yRotation : float;
@HideInInspector
var xRotation : float;
@HideInInspector
var currentYRotation : float;
@HideInInspector
var currentXRotation : float;
@HideInInspector
var yRotationV : float;
@HideInInspector
var xRotationV : float;
var lookSmoothDamp : float = 0.1;
@HideInInspector
var currentAimRatio : float = 1;
var headbobSpeed : float = 1;
@HideInInspector
var headbobStepCounter : float;
var headbobAmountX : float = 1;
var headbobAmountY : float = 1;
@HideInInspector
var parentLastPos : Vector3;
var eyeHeightRatio : float = 0.9;
function Awake ()
{
parentLastPos = transform.parent.position;
}
function Update ()
{
if (transform.parent.GetComponent(PlayerMovementScript).grounded)
headbobStepCounter += Vector3.Distance(parentLastPos, transform.parent.position) * headbobSpeed;
transform.localPosition.x = Mathf.Sin(headbobStepCounter) * headbobAmountX * currentAimRatio;
transform.localPosition.y = (Mathf.Cos(headbobStepCounter * 2) * headbobAmountY * currentAimRatio) + (transform.parent.localScale.y * eyeHeightRatio) - (transform.parent.localScale.y / 2);
parentLastPos = transform.parent.position;
if (currentAimRatio == 1)
ratioZoom = Mathf.SmoothDamp(ratioZoom, 1, ratioZoomV, ratioZoomSpeed);
else
ratioZoom = Mathf.SmoothDamp(ratioZoom, 0, ratioZoomV, ratioZoomSpeed);
camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, ratioZoom);
yRotation += Input.GetAxis("Mouse X") * lookSensitivity * currentAimRatio;
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity * currentAimRatio;
xRotation = Mathf.Clamp(xRotation, clampDown, clampUp);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}
the only thing i changed was a variable i added called pause that meant when i pressed Esc i couldn’t rotate my view, t worked perfectly no Nan errors but when i removed it i got Nan errors even tho it wasn’t part of the original script and didnt effect the part giving me Nan errors.
I get this:
!CompareApproximately (SqrMagnitude (q), 1.0F)
UnityEngine.Quaternion:Euler(Single, Single, Single)
MouseLookScript:Update() (at Assets/script/Player/MouseLookScript.js:69)
And this:transform.rotation assign attempt for ‘playerCamera’ is not valid. Input rotation is { NaN, NaN, NaN, NaN }.
UnityEngine.Transform:set_rotation(Quaternion)
MouseLookScript:Update() (at Assets/script/Player/MouseLookScript.js:69)
I also have errors with my player movement script because i use this for rotation.
If somebody could help me find out whats causing the errors and a way to fix that would be really helpful.
Edit: i tried copying and pasting directly from etteskis resources but still get the error even when i didn’t before, i really don’t know why it suddenly popped up.
FIXED: I think it was just a bug with unity, its a good engine but has a few weird bugs.
anyways, i fixed it by creating a new project and copying all files from old project, that’s all. it was than fixed. I guess the error was just strangely caused when i edited the script (i hadn’t edited that script in a while). It would be handy if these kinda bugs were fixed