/// <summary> /// 以pos为中心各自在宽和高的左右 前后两个方向延伸 /// </summary> /// <param name="self"></param> /// <param name="pos"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public static Vector3 FindRandomPointWithRectangle(this PathfindingComponent self, Vector3 pos, int width, int height) { if (self.NavMesh == 0) { throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}"); } if (width > PathfindingComponent.FindRandomNavPosMaxRadius * 0.001f || height > PathfindingComponent.FindRandomNavPosMaxRadius * 0.001f) { throw new Exception($"pathfinding rectangle is too large,width: {width} height: {height}, max: {PathfindingComponent.FindRandomNavPosMaxRadius}"); } float x = RandomHelper.RandomNumber(-width, width); float z = RandomHelper.RandomNumber(-height, height); Vector3 findpos = new Vector3(pos.x + x, pos.y, pos.z + z); return(self.RecastFindNearestPoint(findpos)); }
public static Vector3 FindRandomPointWithRaduis(this PathfindingComponent self, Vector3 pos, float raduis) { if (self.NavMesh == 0) { throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}"); } if (raduis > PathfindingComponent.FindRandomNavPosMaxRadius * 0.001f) { throw new Exception($"pathfinding raduis is too large,cur: {raduis}, max: {PathfindingComponent.FindRandomNavPosMaxRadius}"); } int degrees = RandomHelper.RandomNumber(0, 360); float r = RandomHelper.RandomNumber(0, (int)(raduis * 1000)) / 1000f; float x = r * Mathf.Cos(MathHelper.DegToRad(degrees)); float z = r * Mathf.Sin(MathHelper.DegToRad(degrees)); Vector3 findpos = new Vector3(pos.x + x, pos.y, pos.z + z); return(self.RecastFindNearestPoint(findpos)); }