Delete Astar Path gride graph around a particular Object

Hello guys !

Could anyone please help me…

I have a zombie in my game that follows the player. In my terrain, i also have some objects (e.g. A fence). If the player goes behind the fence, the zombie cant find its way to go behind the fence, and it collides to the fence.

This is happening because the objects are above the path grids. How can can i delete those triangles where the objects are on ?? I have tried using Navmesh but couldn’t make it function properly. So is there any other way of doing it ?

So to summarize the above, what i basically want to do is just to delete an area in middle of the grid graph

Not that hard, you just have to insert some raycasting code from the PointGraph script.

In GridGenerator.cs:

In the main body, around Line 200, before the functions begin, add these variables:

/// <summary>
		/// Variables for raycasting between nodes, copid from PointGenerator.cs
		/// </summary>
		public GameObject GameController = GameObject.Find("AAAGameControl").gameObject;
		
		[JsonMember]
		/** Layer mask to use for raycast */
		public LayerMask mask;
		
		
		[JsonMember]
		/** Use raycasts to check connections */
		public bool raycast = true;
		
		[JsonMember]
		/** Use thick raycast */
		public bool thickRaycast = true;
		
		[JsonMember]
		/** Thick raycast radius */
		public float thickRaycastRadius = 1;
		
		
		//end of raycasting variables

Replace the code of the function IsValidConnection, around Line 750 with:

/** Returns true if a connection between the adjacent nodes \a n1 and \a n2 is valid. Also takes into account if the nodes are walkable */
		public virtual bool IsValidConnection (GridNode n1, GridNode n2) {
			if (!n1.walkable || !n2.walkable) {
				return false;
			}
			
			if (maxClimb != 0 && Mathf.Abs (n1.position[maxClimbAxis] - n2.position[maxClimbAxis]) > maxClimb*Int3.Precision) {
				return false;
			}
			
			
			
			
			/// <summary>
			/// code for raycasting between nodes, copid from PointGenerator.cs
			/// </summary>
			
			mask |= (1 << LayerMask.NameToLayer("Obstacles"));
			mask |= (1 << LayerMask.NameToLayer("NodeBlock"));
			mask |= (1 << LayerMask.NameToLayer("LightCover"));
			mask |= (1 << LayerMask.NameToLayer("HeavyCover"));

			float dist = Vector3.Distance((Vector3)n1.position, (Vector3)n2.position);
			
			if (raycast) 
			{
				Ray ray = new Ray ((Vector3)n1.position,(Vector3)(n2.position-n1.position));
				Ray invertRay = new Ray ((Vector3)n2.position,(Vector3)(n1.position-n2.position));
				
				if (thickRaycast) 
				{
					if (!Physics.SphereCast (ray,thickRaycastRadius,dist,mask) && !Physics.SphereCast (invertRay,thickRaycastRadius,dist,mask)) 
					{
						//return true;
						return true;
					}
				} 
				else 
				{
					if (!Physics.Raycast (ray,dist,mask) && !Physics.Raycast (invertRay,dist,mask)) 
					{
						//return true;
						return true;
					}
				}
			} 
			else 
			{
				return true;
			}
			//end of raycasting block
			
			
			
			
			
			return false;
		}

Note that I wasn’t able to get the thick raycasting to work. Also note that you have to define the mask LayerMask however you need it yourself.

You can also put a GUO (Graph Update Object) with the required size at the required position and use it’s GetComponent(GraphUpdateScene).Apply(); function to add or delete noce connections.

Furthermore, you can just add one or more empty gameObjects below the fence so they connect with the ground, and add coliders to them and set their layer to one that blocks node connections (this would be the easiest way).