- Home /
How to Get a Point from an Area in Front of an Object for NavMesh
Hello,
I am trying to make more realistic patrol (wandering) AI for my enemy. Originally it could navigate anywhere in the black box Random.Range(-walkPointRange, walkPointRange), but that led to very jittery and unnatural looking movement. Then I figured out how to check if the random point was located in the green cone, but that is of course VERY inefficient, since only a small fraction of points will be valid the enemy will be stuck on idle for a long time.
So instead of getting a random point and checking if it is valid, is there a way to just get a point inside that green cone?
So far I've tried:
leftNav = Quaternion.Euler(0, -45, 0) * transform.forward * walkPointRange;
rightNav = Quaternion.Euler(0, 45, 0) * transform.forward * walkPointRange;
float randomX = Random.Range(leftNav.x, rightNav.x);
float randomZ = Random.Range(leftNav.z, rightNav.z);
With leftNav being the left side of the cone and rightNav being the right side, but I think I am setting up the vectors incorrectly. Any help would be greatly appreciated, thanks!
Your answer
