player can enter the door

This commit is contained in:
Vladimir Koshevarov
2023-03-06 18:54:13 +02:00
parent 667c9901b6
commit ac5dce3507
35 changed files with 29063 additions and 1193 deletions
+19 -16
View File
@@ -22,7 +22,6 @@ public class Player : MonoBehaviour
private Transform _holdPoint;
private AnimationStates _currentAnimation;
private Vector3 _groundDeltaPosition;
public Dictionary<StatsId, Stat> Stats;
public IWorkPlace WorkPlace { get; set; }
@@ -36,17 +35,21 @@ public class Player : MonoBehaviour
private void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
Debug.Log("There's more than one player instance");
return;
}
PlayerPrefs.SetString("lastExitName", string.Empty);
Instance = this;
DontDestroyOnLoad(gameObject);
}
private void Start()
{
TimeManager.OnMinuteChanged += UpdateStatsByClock;
_animator.applyRootMotion = true;
_navAgent.updatePosition = false;
Stats = PlayerStats.CreateInitialStats();
}
@@ -75,7 +78,7 @@ public class Player : MonoBehaviour
switch (_currentTask.Task)
{
case Tasks.Rotate:
_currentTask.UpdateStatus(Rotate(_currentTask.TagretObject._playerArrivePoint.forward));
_currentTask.UpdateStatus(Rotate(_currentTask.TagretObject._interactionPoint.forward));
break;
case Tasks.Move:
if (_currentAnimation == AnimationStates.Sitting)
@@ -83,11 +86,11 @@ public class Player : MonoBehaviour
SetPlayerAnimation(AnimationStates.Standing);
return;
}
_navAgent.SetDestination(_currentTask.TagretObject._playerArrivePoint.position);
_navAgent.SetDestination(_currentTask.TagretObject._interactionPoint.position);
_currentTask.UpdateStatus(MoveToPoint());
break;
case Tasks.Interact:
if (IsPathComplete(_currentTask.TagretObject._playerArrivePoint.position))
if (IsPathComplete(_currentTask.TagretObject._interactionPoint.position))
_currentTask.UpdateStatus(InteractWithObject(_currentTask.TagretObject));
else
{
@@ -101,17 +104,21 @@ public class Player : MonoBehaviour
}
}
public void SetPosition(Vector3 desiredPosition)
{
_navAgent.Warp(desiredPosition);
_navAgent.updatePosition = false;
}
private TaskStatus MoveToPoint()
{
_navAgent.isStopped = false;
SetPlayerAnimation(AnimationStates.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;
_animator.SetFloat(WALK_VELOCITY, velocity.y);
//transform.position = Vector3.MoveTowards(_navAgent.transform.position, _navAgent.pathEndPosition, _navAgent.speed * Time.deltaTime);
// transform.position = _animator.(_navAgent.pathEndPosition);
_animator.SetFloat(WALK_VELOCITY, _navAgent.velocity.magnitude);
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
}
@@ -126,6 +133,7 @@ public class Player : MonoBehaviour
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude < 0.2f)
{
SetPlayerAnimation(AnimationStates.Idle);
_navAgent.isStopped = true;
return true;
}
}
@@ -176,11 +184,6 @@ public class Player : MonoBehaviour
return false;
}
private void OnAnimatorMove()
{
transform.position = _navAgent.nextPosition;
}
public void AddTask(PlayerTasks task)
{
_tasks.Enqueue(task);