21 lines
689 B
C#
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;
|
|
}
|
|
} |