You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
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;
|
|
|
|
private float rotationXMin = 350.0f;
|
|
private float rotationXMax = 350.0f;
|
|
private float rotationYMin = -60.0f;
|
|
private float rotationYMax = 80.0f;
|
|
|
|
private float rotationXOffset = 0.0f;
|
|
private float rotationYOffset = 180.0f;
|
|
|
|
private float rotationXModifier = 1.0f;
|
|
private float rotationYModifier = 1.0f;
|
|
private float rotationZModifier = 1.0f;
|
|
|
|
private float previousX;
|
|
private float previousY;
|
|
private 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|