TowerDefenseGame/Assets/Scripts/Runtime/Core/Utils/NavMeshUtils.cs
Nico 62b981f440 Add knockbock gaurd against being pushed out of bounds
Further develop on attacking and taking damage states
2025-07-25 17:52:08 -07:00

21 lines
689 B
C#

using UnityEngine;
using UnityEngine.AI;
using static UnityEditor.PlayerSettings;
public static class NavMeshUtils {
public static bool IsWalkable(Vector3 origin, Vector3 velocity, float navMeshCheckRadius = 0.2f) {
Vector3 target = origin + velocity * Time.fixedDeltaTime;
//// 1. Physics obstacle check (optional, but good to avoid wall collisions)
//if (Physics.Linecast(origin, target, obstacleMask))
// return false;
// 2. Check if point is still on the NavMesh
if (!NavMesh.SamplePosition(target, out var hit, navMeshCheckRadius, NavMesh.AllAreas))
return false;
return true;
return (hit.position - target).sqrMagnitude < 0.04f;
}
}