Files
Cielonos/Assets/Scripts/MainGame/Characters/Automata/Subcontrollers/AutomataLandMovementSubcontroller.cs
SoulliesOfficial f7af60351b 阶段性完成
2025-12-08 05:27:53 -05:00

79 lines
2.8 KiB
C#

using SLSFramework.General;
using UnityEngine;
using UnityEngine.AI;
namespace Cielonos.MainGame.Characters
{
public class AutomataLandMovementSubcontroller : LandMovementSubcontroller
{
public NavMeshAgent navMeshAgent => (owner as Automata).navMeshAgent;
public LerpFloat moveSpeedZ;
public override void Initialize()
{
base.Initialize();
moveSpeedZ = new LerpFloat(0f, 5f);
}
private Vector3 lastDirection;
public override void OnAnimatorMove()
{
if (Time.deltaTime == 0 || owner.statusSm.isDead)
{
return;
}
if (navMeshAgent != null)
{
//if (!Enemy.isAnalogMoving)
{
float distanceVelocity = navMeshAgent.velocity.magnitude;
float angularVelocity = Vector3.Angle(lastDirection, transform.forward) / Time.deltaTime;
moveSpeedZ.targetValue = distanceVelocity + (angularVelocity * 0.1f);
moveSpeedZ.Update(0.2f, 1);
animator.SetFloat("MoveSpeedZ", moveSpeedZ.currentValue);
}
/*else
{
Vector3 moveDirection = Enemy.navMeshAgent.velocity;
targetMovementSpeedX = Vector3.Dot(moveDirection, transform.right);
targetMovementSpeedZ = Vector3.Dot(moveDirection, transform.forward);
movementSpeedX = Mathf.Lerp(movementSpeedX, targetMovementSpeedX, 0.1f);
movementSpeedZ = Mathf.Lerp(movementSpeedZ, targetMovementSpeedZ, 0.1f);
Enemy.animator.SetFloat("MovementSpeedX", movementSpeedX);
Enemy.animator.SetFloat("MovementSpeedZ", movementSpeedZ);
movementSpeed = new Vector3(movementSpeedX, 0, movementSpeedZ).magnitude;
}*/
}
base.OnAnimatorMove();
InitiativeMove();
lastDirection = transform.forward;
}
protected override void InitiativeMove()
{
if (navMeshAgent.enabled)
{
navMeshAgent.Move(finalMovementVelocity);
}
else
{
if (owner.collisionSc.useCharacterController)
{
owner.collisionSc.characterController.Move(finalMovementVelocity);
}
else
{
Vector3 startPosition = owner.collisionSc.mainRigidbody.position;
owner.collisionSc.mainRigidbody.MovePosition(startPosition + finalMovementVelocity);
}
}
}
}
}