added: some headtracking
This commit is contained in:
@@ -4,6 +4,14 @@ using UnityEngine;
|
||||
namespace Reset.Units{
|
||||
public class UnitAnimation : UnitComponent{
|
||||
public Animator modelAnimator;
|
||||
|
||||
public Transform headBone;
|
||||
public Transform neckBone;
|
||||
|
||||
public Vector3 headRotOffset;
|
||||
public Vector3 neckRotOffset;
|
||||
|
||||
public Vector3 rotationLimit;
|
||||
|
||||
// Temporary
|
||||
private float inputMagnitude;
|
||||
@@ -18,8 +26,47 @@ namespace Reset.Units{
|
||||
} catch (Exception e) {
|
||||
Debug.LogError($"Failed in setting X and Y move direction floats: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void LateUpdate(){
|
||||
TurnHead();
|
||||
}
|
||||
|
||||
void TurnHead(){
|
||||
var targetObject = (Unit.Combat as EnemyCombat).UnitTarget;
|
||||
|
||||
if (targetObject) {
|
||||
Vector3 headDirToTarget = headBone.position.DirectionTo(targetObject.transform.position);
|
||||
Vector3 neckDirToTarget = neckBone.position.DirectionTo(targetObject.transform.position);
|
||||
|
||||
Quaternion newHeadRot = Quaternion.LookRotation(headDirToTarget);
|
||||
Quaternion newNeckRot = Quaternion.LookRotation(neckDirToTarget);
|
||||
|
||||
Quaternion offsetHeadRot = Quaternion.Euler(headRotOffset);
|
||||
Quaternion offsetNeckRot = Quaternion.Euler(neckRotOffset);
|
||||
|
||||
Debug.Log(offsetNeckRot.eulerAngles);
|
||||
|
||||
Vector3 clampedHeadRot = new Vector3(
|
||||
Mathf.Clamp(newHeadRot.eulerAngles.x, -rotationLimit.x, rotationLimit.x),
|
||||
Mathf.Clamp(newHeadRot.eulerAngles.y, -rotationLimit.y, rotationLimit.y),
|
||||
Mathf.Clamp(newHeadRot.eulerAngles.z, -rotationLimit.z, rotationLimit.z)
|
||||
);
|
||||
|
||||
Vector3 clampedNeckRot = new Vector3(
|
||||
Mathf.Clamp(newNeckRot.eulerAngles.x, -rotationLimit.x, rotationLimit.x),
|
||||
Mathf.Clamp(newNeckRot.eulerAngles.y, -rotationLimit.y, rotationLimit.y),
|
||||
Mathf.Clamp(newNeckRot.eulerAngles.z, -rotationLimit.z, rotationLimit.z)
|
||||
);
|
||||
|
||||
Quaternion outputHeadRot = Quaternion.Lerp(headBone.transform.rotation, Quaternion.Euler(clampedHeadRot), .8f);
|
||||
Quaternion outputNeckRot = Quaternion.Lerp(neckBone.transform.rotation, Quaternion.Euler(clampedNeckRot), .2f);
|
||||
|
||||
headBone.transform.rotation = offsetHeadRot * headBone.transform.rotation * outputHeadRot;
|
||||
neckBone.transform.rotation = (offsetNeckRot * neckBone.transform.rotation * outputNeckRot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user