using UnityEngine;
namespace NightclubArcadia.Player.Math
{
///
/// Pure math helpers shared by click-to-move and camera pan.
///
public static class MotionInputMath
{
///
/// Converts a NavMeshAgent desired velocity into the camera-relative
/// Vector2 that ThirdPersonController expects on StarterAssetsInputs.move.
///
public static Vector2 WorldToCameraRelativeInput(Vector3 worldVelocity, float agentSpeed, float cameraYaw)
{
if (worldVelocity.sqrMagnitude < 0.0001f || agentSpeed <= 0f)
{
return Vector2.zero;
}
var horizontal = new Vector3(worldVelocity.x, 0f, worldVelocity.z);
var magnitude = horizontal.magnitude;
var fraction = Mathf.Clamp01(magnitude / agentSpeed);
var local = Quaternion.Euler(0f, -cameraYaw, 0f) * horizontal.normalized;
return new Vector2(local.x, local.z) * fraction;
}
///
/// Converts screen-space pointer delta into a world-plane pan offset.
/// Drag direction is inverted so the world follows the cursor.
///
public static Vector3 ScreenDeltaToWorldPan(
Vector2 pixelDelta,
Vector3 camRight,
Vector3 camForward,
float metresPerPixel)
{
var forward = Vector3.ProjectOnPlane(camForward, Vector3.up).normalized;
return (-pixelDelta.x * camRight + -pixelDelta.y * forward) * metresPerPixel;
}
}
}