using System;
using UnityEngine;
namespace Framework.Actors {
/// Helper methods for head controllers
public static class HeadControllerHelper {
/// Retrieves the look direction in the global coordinate system
/// Component by which the look direction is controlled
/// Direction the actor is looking in
public static Vector3 GetGlobalLookDirection(this IHeadController headComponent) {
Quaternion orientation = (
headComponent.HeadBaseOrientation * headComponent.LocalHeadOrientation
);
return orientation * Vector3.forward;
}
/// Sets the look direction in the global coordinate system
/// Component on which the look direction will be set
/// Direction the actor will look in
public static void SetGlobalLookDirection(
this IHeadController headController, Vector3 direction
) {
Vector3 upwards = headController.HeadBaseOrientation * Vector3.up;
Quaternion globalOrientation = Quaternion.LookRotation(direction, upwards);
Quaternion localOrientation = Quaternion.Inverse(
headController.HeadBaseOrientation
) * globalOrientation;
// This may be outside the head movement range, but that's okay:
// a head controller is supposed to clamp upon assignment and trigger
// the ExcessHeadRotation event to apply the clamped-off part to the body.
headController.LocalHeadOrientation = localOrientation;
}
}
} // namespace Framework.Actors