Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ammar_qbaniha · May 21, 2014 at 07:50 PM · aipathfindingpathastar

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · May 22, 2014 at 03:56 AM

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).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I go about making a 2d platform enemy ai 1 Answer

GridGraph A* : how to verify if a point is attainable and how to use different graphs for different agents 0 Answers

How do I get my patrolling enemies to go back to the patrol point they had not gotten to because they chased the player? 0 Answers

Astar Pathfinding ai moves more nodes than it should 0 Answers

Colliders and Astar 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges