small anim fixes

This commit is contained in:
2023-02-28 07:28:57 +02:00
parent c7d6dc5772
commit 81b266c288
4 changed files with 1209 additions and 45 deletions
+20 -29
View File
@@ -83,51 +83,40 @@ public class Player : MonoBehaviour
}
}
private TaskStatus MoveToPoint()
{
SetPlayerState(ActionStates.Walking);
var worldDeltaPosition = _navAgent.nextPosition - transform.position;
_groundDeltaPosition.x = Vector3.Dot(transform.right, worldDeltaPosition);
_groundDeltaPosition.y = Vector3.Dot(transform.forward, worldDeltaPosition);
Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero;
var shouldMove = velocity.magnitude > 0.025f && _navAgent.remainingDistance > _navAgent.radius;
if (_currentState == ActionStates.Sitting)
{
SetPlayerState(ActionStates.Standing);
}
_currentState = shouldMove ? ActionStates.Walking : ActionStates.Idle;
SetPlayerState(ActionStates.Walking);
_animator.SetFloat(WALK_VELOCITY, velocity.y);
return pathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
}
private bool pathComplete(Vector3 destination)
{
if (Vector3.Distance(destination, _navAgent.transform.position) <= _navAgent.radius)
{
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude == 0f)
{
SetPlayerState(ActionStates.Idle);
return true;
}
}
return false;
}
public void Rotate(Vector3 target)
{
Quaternion rotation = Quaternion.LookRotation(target);
transform.rotation = rotation;
}
private bool pathComplete(Vector3 destination)
{
if (Vector3.Distance(destination, _navAgent.transform.position) <= _navAgent.radius)
{
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude == 0f)
{
SetPlayerState(ActionStates.Idle);
return true;
}
}
return false;
}
private TaskStatus InteractWithObject(BaseInteractableObject interactableObject)
{
@@ -137,6 +126,8 @@ public class Player : MonoBehaviour
public void SetPlayerState(ActionStates newState)
{
if(newState== _currentState)
{ return; }
switch (newState)
{
case ActionStates.Idle: