mostly fixed animations

This commit is contained in:
2023-02-27 23:30:00 +02:00
parent 26bb1878c5
commit c7d6dc5772
44 changed files with 432070 additions and 281010 deletions
+25 -9
View File
@@ -5,7 +5,7 @@ using UnityEngine.AI;
public enum Tasks { Move, Interact };
public enum TaskStatus { Waiting, InProgress, Complete };
public enum ActionStates { Idle, Walking, Sleeping, Sitting };
public enum ActionStates { Idle, Walking, Sleeping, Sitting, Standing };
public class Player : MonoBehaviour
{
public static Player Instance { get; private set; }
@@ -27,7 +27,6 @@ public class Player : MonoBehaviour
private const string FALL_DOWN = "Fall";
private const string SIT_DOWN = "SitDown";
private const string STAND_UP = "StandUp";
private const string WALK = "Walk";
private const string WALK_VELOCITY = "WalkVelocity";
@@ -88,19 +87,25 @@ public class Player : MonoBehaviour
private TaskStatus MoveToPoint()
{
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.Sleeping)
{
_currentState = shouldMove ? ActionStates.Walking : ActionStates.Idle;
SetPlayerState(ActionStates.Walking);
_animator.SetFloat(WALK_VELOCITY, velocity.y);
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;
}
@@ -136,8 +141,6 @@ public class Player : MonoBehaviour
{
case ActionStates.Idle:
_animator.SetBool(WALK, false);
_animator.SetBool(SIT_DOWN, false);
break;
case ActionStates.Walking:
_animator.SetBool(WALK, true);
@@ -147,10 +150,23 @@ public class Player : MonoBehaviour
case ActionStates.Sitting:
_animator.SetBool(SIT_DOWN, true);
break;
case ActionStates.Standing:
_animator.SetBool(SIT_DOWN, false);
break;
}
_currentState = newState;
}
bool isAnimationStatePlaying(int animLayer, string stateName)
{
if (_animator.GetCurrentAnimatorStateInfo(animLayer).IsName(stateName) &&
_animator.GetCurrentAnimatorStateInfo(animLayer).normalizedTime < 1.0f)
return true;
else
return false;
}
private void OnAnimatorMove()
{
transform.position = _navAgent.nextPosition;