From 4142126258f035e219b0333efa8266b11968e540 Mon Sep 17 00:00:00 2001 From: David Huss <dh@atoav.com> Date: Tue, 16 Jun 2020 21:19:05 +0200 Subject: [PATCH] Fix initial orientation --- SmoothMouseLook.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/SmoothMouseLook.cs b/SmoothMouseLook.cs index b954daf..c885504 100644 --- a/SmoothMouseLook.cs +++ b/SmoothMouseLook.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; -[AddComponentMenu("SmoothMouseLook ")] +[AddComponentMenu("MouseLook ")] public class SmoothMouseLook : MonoBehaviour { // The speed at which we turn (Mouse Sensitivity) @@ -58,8 +58,8 @@ public class SmoothMouseLook : MonoBehaviour // first Child of type Camera. If none is found head = null head = GetComponentInChildren<Camera>().transform; - // Cache the orientation of body and head. - // This errors if head (Camera Child) was not found + // Cache the orientation of body and head. This errors if head was not + // found bodyStartOrientation = transform.localRotation; headStartOrientation = head.transform.localRotation; @@ -123,8 +123,9 @@ public class SmoothMouseLook : MonoBehaviour // Compute rotations by rotating around a fixed axis (rotate yaw-degrees // around the up direction for the body, and pitch degrees around the // right direction for the head). - var bodyRotation = Quaternion.AngleAxis(yaw, Vector3.up); - var headRotation = Quaternion.AngleAxis(pitch, Vector3.right); + // Note: 90 deg need to be added, to get the initial orientation right + var bodyRotation = Quaternion.AngleAxis(yaw + 90, Vector3.up); + var headRotation = Quaternion.AngleAxis(pitch + 90, Vector3.right); // Finally combine the rotations for body and head with the start rotations transform.localRotation = bodyRotation * bodyStartOrientation; -- GitLab