Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 1337GameDev · Jan 03, 2013 at 10:20 PM · aipathfindinggridfollowgraph

ai pathfinding project getting started scene problems

I cannot get the getting started scene to work fully. The scene is set up according to the documentation, but it doesn't seem to work. I get the ai character (a capsule in this case) to move and try to follow the path, but it doesn't follow the graph all the time. In the following video you can see that it goes off the graph and turns to early and then doesn't go high enough (and therefore gets caught on the edge and moves down towards the goal due to colliding with the wall and having to walk into the walk). What could cause this?

Here's the video: Video of AI in editor

Here's the code for the testAStar script:

 using UnityEngine;
 using System.Collections;
 
 using Pathfinding;
 
 public class testAStar : MonoBehaviour 
 {
     
     //The point to move to
     public Vector3 targetPosition;
     public Vector3 targetDefaultPos = new Vector3(0,0,0);
     public GameObject targetObj;
     
     public Seeker seeker;
     
     public CharacterController controller;
     
     //The calculated path
     public Path path;
     
     //The AI's speed per second
     public float speed = 100;
     
     //The max distance from the AI to a waypoint for it to continue to the next waypoint
     public float nextWaypointDistance = 10f;
  
     //The waypoint we are currently moving towards
     private int currentWaypoint = 0;
  
     public void Awake()
     {
         targetObj = (GameObject)GameObject.Find("target");
     }
     
     public void Start() 
     {
         //Get a reference to the Seeker component we added earlier
         seeker = transform.parent.GetComponent<Seeker>();
         controller = transform.parent.GetComponent<CharacterController>();
         //if(targetDefaultPos.Equals(Vector3.zero) )
         //{
             targetPosition = targetObj.transform.position;
         //}
         //else
         //{
             //targetPosition = targetDefaultPos;
         //}
         //Start a new path to the targetPosition, return the result to the OnPathComplete function
         seeker.StartPath(transform.position,targetPosition, OnPathComplete);
     }
     
     public void OnPathComplete(Path p) 
     {
         Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);
         if (!p.error) 
         {
             path = p;
             //Reset the waypoint counter
             currentWaypoint = 0;
         }
         
     }
  
     public void FixedUpdate() 
     {
         if (path == null) 
         {
             //We have no path to move after yet
             return;
         }
         
         if (currentWaypoint >= path.vectorPath.Length) 
         {
             Debug.Log ("End Of Path Reached");
             return;
         }
         
         //Direction to the next waypoint
         Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
         Debug.Log ("Dir: " + dir.ToString() + " to waypoint " + currentWaypoint );
         dir *= speed * Time.fixedDeltaTime;
         controller.SimpleMove(dir);
         
         //Check if we are close enough to the next waypoint
         //If we are, proceed to follow the next waypoint
         if (Vector3.Distance(transform.position,path.vectorPath[currentWaypoint] ) < nextWaypointDistance ) 
         {
             currentWaypoint++;
             return;
         }
         
     }
     
     public void Update()
     {
         
     }
     
 }
 

My gameObject i attached the seeker, CharacterController and testAStar script in a hierarchy like this:

EmptyGameObject (parent) -- [CharacterController and Seeker components attached here]

        |-Capsule GameObject (child) -- [testAStar script]

I do reference the seeker and character controller correctly.

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 Halleflux · Jul 27, 2013 at 06:04 AM

Your nextWaypointDistance is too high, it's going to the next point too early. Reduce it by a large amount.

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

9 People are following this question.

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

Related Questions

Pathfinding unity 3 Answers

How to simulate Turns in Turn Based Strategy Game? 1 Answer

Sidescroller NPC follows Player 0 Answers

RTS Grid and Pathfinding 2 Answers

grid pathing system 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