From b1bd6379ed9e6adad0c30b0a4c498cc782e8defb Mon Sep 17 00:00:00 2001 From: Stedd Date: Sun, 3 Sep 2023 15:14:01 +0200 Subject: [PATCH] Added destination validation for move command --- Assets/PlayerMovement.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Assets/PlayerMovement.cs b/Assets/PlayerMovement.cs index c3898a4..e1f24af 100644 --- a/Assets/PlayerMovement.cs +++ b/Assets/PlayerMovement.cs @@ -14,7 +14,10 @@ public class PlayerMovement : NetworkBehaviour [Command] private void CmdMove(Vector3 destination) { - _navMeshAgent.SetDestination(destination); + if (NavMesh.SamplePosition(destination, out NavMeshHit hit, 1f, NavMesh.AllAreas)) + { + _navMeshAgent.SetDestination(hit.position); + } } #endregion