• 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
2
Question by IBDelta · Feb 20, 2011 at 08:11 PM · followpath

Angry Ant's Path following

I have been trying to get a simple AI working with Angry Ant's path tool, I've followed the tutorial so I've got a path to follow but I cannot work out how to make the object follow the it. Is there a simple example project available so I can see it in action or could someone please tell me how access the path data?

P.s. I'm using c# if you want to post code.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by IBDelta · Feb 22, 2011 at 02:29 PM

I finally got the answer to my own question. For those who wish to know, the two lines I was missing are as follows;

targWayFrom = m_CurrentPath.Segments[WayCnt].From as Waypoint;
targWayTo = m_CurrentPath.Segments[WayCnt].To as Waypoint;

They work from within the DemoSeeker script. WayCnt is the current connection you are accessing, the first position the object moves to is Segments[0].From

Comment
Add comment · Show 1 · 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
avatar image Ganesh Faterpekar · Apr 04, 2011 at 12:48 PM 0
Share

Hi I am trying the same, can you post the full example of moving an object along the path in Angry Ant's path

thanks in advance

avatar image
0

Answer by I B Delta 9 · May 12, 2011 at 07:56 AM

This was the script I got working. It's designed to use the Mixamo zombie character. I had to edit the zombie controller to accept script driven stimulus instead of a keystroke. I'll be doing a tutorial on how to make path and behave work together and I'll post a link here if I can. I don't do a lot of coding in summer so it will have to wait a bit.

using UnityEngine; using System.Collections;

[RequireComponent (typeof (Navigator))] public class DemoSeeker : MonoBehaviour { public Transform m_Target;

 public Path m_CurrentPath;

 public float speed = 3.0F;
 public float rotateSpeed = 3.0F;
 public float ZombieRotate = 0.0F;
 public float targetDir=0.0f;    
 public Vector3 targVect=Vector3.zero;   
 public int PathCnt;
 public int WayCnt;
 public int NodeCnt;
 public Connection[] WaypointObj; 
 public int WaypointCnt;
 public int WayPathCnt;
 public Connection targObj;
 public Waypoint targWayFrom;
 public Waypoint targWayTo;
 public float WayDist;
 public bool ZombieMove=false;
 public static bool ZomFwd=false;
 public static bool ZomLft=false;
 public static bool ZomRgt=false;
 public static Vector3 RelativePos;
 public int TurnCnt=0;

 void Start ()
 {
     m_Target=GameObject.FindWithTag("Player").transform;
     GetComponent<Navigator> ().RegisterWeightHandler ("Water", OnHandleWaterWeight);
     GetComponent<Navigator>().targetPosition=m_Target.position;
     GetComponent<Navigator>().ReSeek();
     PathCnt=0;
     WayCnt=0;
     NodeCnt=0;
     TurnCnt=0;
 }

     // Update is called once per frame
 void Update () 
 {
     PathCnt++;
     if(PathCnt==5)
     {
         targWayFrom = m_CurrentPath.Segments[WayCnt].From as Waypoint;
         targWayTo = m_CurrentPath.Segments[WayCnt].To as Waypoint;
         ZombieMove=true;
         PathCnt=0;
         if ((transform.position.x<targWayFrom.Position.x+2)&&(transform.position.x>targWayFrom.Position.x-2)&&(transform.position.z<targWayFrom.Position.z+2)&&(transform.position.z>targWayFrom.Position.z-2))
         {
             WayCnt++;
         }
     }
     if(ZombieMove==true)
     {
         ZomRgt=false;
         ZomLft=false;

         TurnCnt++;
         ZomFwd=true;
         if(TurnCnt==5)
         {
             TurnCnt=0;
             RelativePos=transform.InverseTransformPoint(targWayFrom.Position);
             if (RelativePos.x > 0) 
             {
                 ZomRgt=true;
                 ZomLft=false;
             }
             if (RelativePos.x < 0) 
             {
                 ZomRgt=false;
                 ZomLft=true;
             }
         }
     }
 }


 void OnNewPath (Path path)
 // When pathfinding via Navigator.targetPosition
 {
     Debug.Log ("Received new Path from " + path.StartNode + " to " + path.EndNode + ". Took " + path.SeekTime + " seconds.");
     m_CurrentPath = path;
 }


 void OnTargetUnreachable ()
 // When pathfinding via Navigator.targetPosition
 {
     Debug.Log ("Could not pathfind to target position");
     m_CurrentPath = null;
 }


 void OnPathAvailable (Path path)
 // When pathfinding via Navigator.RequestPath (startPositio, endPosition)
 {
     Debug.Log ("Requested Path from " + path.StartNode + " to " + path.EndNode + " is now available. Took " + path.SeekTime + " seconds.");
 }


 void OnPathUnavailable ()
 // When pathfinding via Navigator.RequestPath (startPositio, endPosition)
 {
     Debug.Log ("The requested path could not be established.");
 }


 void OnPathInvalidated (Path path)
 // When a path requested by a Navigator on this GameObject is no longer valid - due to a connection or node disabling or removal
 {
     Debug.Log ("The path from " + path.StartNode + " to " + path.EndNode + " is no longer valid.");
 }


 void OnGUI ()
 {
     if (GUILayout.Button ("Pathfind"))
     {
         GetComponent<Navigator> ().targetPosition = m_Target.position;
     }
     if (GUILayout.Button ("ReSeek"))
     {
         GetComponent<Navigator> ().ReSeek ();
     }
 }


 void OnDrawGizmos ()
 {
     if (m_CurrentPath == null)
     {
         return;
     }

     m_CurrentPath.OnDrawGizmos ();
 }


 float OnHandleWaterWeight (object obj)
 {
     return 3.0f;
 }

}

P.s. Mr Ant, if you happen to read this, your path system is smarter than my dog. She managed to get herself stuck in a tennis court with an open gate this morning :-)

Comment
Add comment · Show 1 · 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
avatar image SrNull · Aug 14, 2011 at 04:32 PM 0
Share

Hello, i´m reading your code and trying to understand it, until now what i know it's i have to look for the WayPoints and make a transform.position directed to that WayPoint, when the position is equal to targWayFrom.Position(x+2,y+2,z+2) i look for the next one in the 'm_CurrentPath.Segments' array, am i right?? Thanks for advance.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How do I instantiate a projectile along the path of a raycast? 0 Answers

Dog chasing my player on curved path? 2 Answers

Need Help: Unity draw-to-follow? 0 Answers

Object following the path 3 Answers

Selectable Paths 1 Answer


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