86 lines
2.9 KiB
C#
86 lines
2.9 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();
|
|
navMeshAgent.isStopped = true;
|
|
moveSpeedZ = new LerpFloat(0f, 5f);
|
|
}
|
|
|
|
private Vector3 lastDirection;
|
|
|
|
protected override void OnAnimatorMove()
|
|
{
|
|
if (Time.deltaTime == 0 || owner.statusSm.isDead)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (navMeshAgent != null)
|
|
{
|
|
if (!navMeshAgent.isStopped)
|
|
{
|
|
float distanceVelocity = navMeshAgent.velocity.magnitude;
|
|
float angularVelocity = Vector3.Angle(lastDirection, transform.forward) / Time.deltaTime;
|
|
moveSpeedZ.targetValue = distanceVelocity + (angularVelocity * 0.1f);
|
|
}
|
|
else
|
|
{
|
|
moveSpeedZ.targetValue = 0f;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |