Files
Cielonos/Assets/Scripts/MainGame/Characters/Automata/Subcontrollers/AutomaticLandMovementSubcontroller.cs
SoulliesOfficial ef7b479712 initial
2025-11-25 08:19:33 -05:00

73 lines
2.5 KiB
C#

using SLSFramework.General;
using UnityEngine;
using UnityEngine.AI;
namespace Cielonos.MainGame.Characters
{
public class AutomaticLandMovementSubcontroller : LandMovementSubcontroller
{
public NavMeshAgent navMeshAgent => (owner as Automata).navMeshAgent;
public LerpFloat moveSpeedZ;
public override void Initialize()
{
base.Initialize();
moveSpeedZ = new LerpFloat(0f, 5f);
}
public override void OnAnimatorMove()
{
if (Time.deltaTime == 0)
{
return;
}
if (navMeshAgent != null)
{
//if (!Enemy.isAnalogMoving)
{
moveSpeedZ.targetValue = navMeshAgent.velocity.magnitude;
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();
}
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);
}
}
}
}
}