92 lines
3.3 KiB
C#
92 lines
3.3 KiB
C#
using Code.Infrastructure.Generators;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Infrastructure.Camera.CameraStates
|
|
{
|
|
[State(typeof(CameraMode),typeof(CameraStateMachineContext), true)]
|
|
public partial class ThirdPersonState : BaseCameraState
|
|
{
|
|
public ThirdPersonState(CameraStateMachineContext context, EventBus.EventBus eventBus) : base(context, eventBus)
|
|
{
|
|
}
|
|
|
|
public override CameraMode myState => CameraMode.ThirdPerson;
|
|
protected override void OnEnterState()
|
|
{
|
|
}
|
|
|
|
protected override void OnExitState()
|
|
{
|
|
}
|
|
|
|
protected override void HandleRotationInput(float deltaTime, Vector3 rotationInput, out Quaternion q)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
private Transform _carTarget;
|
|
private Rigidbody _carRigidbody;
|
|
|
|
public void SetFollowTarget(Transform carTarget, Rigidbody carRigidbody)
|
|
{
|
|
_carTarget = carTarget;
|
|
_carRigidbody = carRigidbody;
|
|
}
|
|
|
|
private Vector3 _lookAtOffset = new Vector3(0, 1.5f, 0);
|
|
protected override void HandlePosition(float deltaTime, object targetRotation)
|
|
{
|
|
Fuck();
|
|
}
|
|
|
|
private void Fuck()
|
|
{
|
|
// Автоматическое вращение вокруг машины
|
|
Vector3 targetPosition = CalculateFollowPosition();
|
|
|
|
// Плавное перемещение
|
|
|
|
Vector3 velocity = _carRigidbody ? _carRigidbody.linearVelocity : new Vector3();
|
|
// Context.cameraLoadedData.Camera.transform.DOMove(targetPosition,
|
|
// Context.cameraLoadedData.SettingsConfigs[CameraMode.ThirdPerson].followSharpness);
|
|
Context.cameraLoadedData.Camera.transform.position = Vector3.SmoothDamp(
|
|
Context.cameraLoadedData.Camera.transform.position,
|
|
targetPosition,
|
|
ref velocity,
|
|
Context.cameraLoadedData.SettingsConfigs[CameraMode.ThirdPerson].followSharpness
|
|
);
|
|
|
|
// Направление взгляда с опережением
|
|
Vector3 lookTarget = _carTarget.position +
|
|
_carTarget.forward * Context.cameraLoadedData.SettingsConfigs[CameraMode.ThirdPerson].defaultDistance +
|
|
_lookAtOffset;
|
|
|
|
Context.cameraLoadedData.Camera.transform.LookAt(lookTarget);
|
|
}
|
|
|
|
private Vector3 _followOffset = new Vector3(0, 3, -8);
|
|
|
|
private Vector3 CalculateFollowPosition()
|
|
{
|
|
Vector3 basePosition = _carTarget.position +
|
|
_carTarget.TransformDirection(_followOffset);
|
|
|
|
// Динамическое смещение на основе скорости
|
|
if (!_carRigidbody) return basePosition;
|
|
|
|
var speedFactor = Mathf.Clamp01(_carRigidbody.linearVelocity.magnitude / 50f);
|
|
var speedOffset = _carTarget.forward * (speedFactor * -3f);
|
|
basePosition += speedOffset;
|
|
|
|
return basePosition;
|
|
}
|
|
public override void Update()
|
|
{
|
|
}
|
|
|
|
public override void LateUpdate()
|
|
{
|
|
Fuck();
|
|
}
|
|
}
|
|
} |