using System.Collections; using System.Collections.Generic; using UnityEngine; using SiegeSong; namespace SiegeSong { public class HeadTurn : MonoBehaviour { public Transform HeadBone; public Transform RibcageBone; public Transform LookTarget; public PlayerCameraManager CameraManager; public ActorMotor Motor; public float RotationXMin = 350.0f; public float RotationXMax = 350.0f; public float RotationYMin = -60.0f; public float RotationYMax = 80.0f; public float RotationXOffset = 0.0f; public float RotationYOffset = 180.0f; public float RotationXModifier = 1.0f; public float RotationYModifier = 1.0f; public float RotationZModifier = 1.0f; float previousX; float previousY; float previousZ; void Start() { } void LateUpdate() { if (Motor.Moving == false) { var direction = new Vector3(1, -1, 1); if (LookTarget == null) direction = new Vector3( (CameraManager.ActiveCamera.transform.rotation.eulerAngles.x + RotationXOffset) * RotationXModifier, (CameraManager.ActiveCamera.transform.rotation.eulerAngles.y + RotationYOffset) * RotationYModifier, -CameraManager.ActiveCamera.transform.rotation.eulerAngles.z * RotationZModifier); else direction = LookTarget.position - HeadBone.position; var resetingHeadTurn = true; if (direction.y - RotationYOffset > RotationYMax) { previousY = direction.y; resetingHeadTurn = false; } if (direction.y + RotationYOffset < RotationYMin) { previousY = direction.y; resetingHeadTurn = false; } if (resetingHeadTurn) { direction.y = previousY; resetingHeadTurn = false; } else { HeadBone.eulerAngles = direction; } } } } }