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
2
Question by Pixelstudio · Nov 14, 2009 at 01:49 PM · aipathsteeringcs0246path-finding

unitysteer and path

Hello,

i'm trying to implement unitysteer with path combined! first i have build opon the path demo to figure Path out. i got it working and my object is following a path.

Now i want it to combine with unitysteer. i proberly need to use AngryAntPathway to constuct my pathway from an arraylist of path and such. But i could not get it to work. perhaps any1 has an example?

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
2
Wiki

Answer by Ricardo · Nov 14, 2009 at 02:20 PM

Here's some sample code, snipped from a larger project. You'll need a MonoBehavior that is an ISearchMonitor (for Path).

public class Ship : MonoBehaviour, ISearchMonitor, IRadarReceiver {

In this case we have three properties; the first is the list of nodes returned by Path, the second a path seeker, and finally a UnitySteer PathFollower vehicle.

protected ArrayList path;
protected Seeker seeker;
private PathFollower shipVehicle;

On the behavior start we initialize the PathFollower vehicle to the current object's transform. Notice that this vehicle did not move vertically, but that was specific my implementation case.

protected void Start () {
    shipVehicle = new PathFollower(this.transform, 1, null, radius);
    shipVehicle.MovesVertically = false;
    shipVehicle.MinCollisionTime = 2;
    shipVehicle.MaxSpeed = maxSpeed;
    shipVehicle.Mass = 0.1f;
    shipVehicle.MaxForce = maxForce;
    shipVehicle.AvoidDeg = 30;
}

The GoTo method is pretty much Path boilerplate - it creates a seeker, adds a monitor and starts it on the control. I'm just adding it here for reference purposes.

public void GoTo(Vector3 destination)
{
    seeker = new Seeker( transform.position, destination, maxFrameTime, radius, null );
    if( seeker.Start != null && seeker.End != null )
    {
        this.Moving = true;
        seeker.AddMonitor(this);
        Control.Instance.StartSeeker( seeker );
    }
}

When we receive a notification that the search was completed, we create a UnitySteer AngryAntPathway based on the resulting path ArrayList, and pass it to the vehicle for following.

public void OnSearchCompleted( Seeker seeker ) { this.seeker = null; this.path = seeker.Solution; this.destination = seeker.To;

 if (this.path == null) 
 {
     return;
 }

 if (seeker.Start != seeker.End)
 {
     shipVehicle.Pathway = new AngryAntPathway(path, 0.25f, false);
 }
 else
 {
     shipVehicle.Moving = false;
 }

}

And finally, if we have a path, on Update we tell the vehicle to update our position.

protected void Update () {
    if (path == null) return;
    shipVehicle.Update(Time.deltaTime);
}

That's it. :-)

Comment
Add comment · Show 7 · 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 Pixelstudio · Nov 14, 2009 at 04:07 PM 0
Share

Hi there, i got it almost working i think.

But for some reason my object goes straight to the final destination, just seems to ignore the path.. any clue what that could be ? I got my code just as yours but with some things fron the path demo.

avatar image Ricardo · Nov 14, 2009 at 08:55 PM 0
Share

The code looks O$$anonymous$$ at a glance. Check out the path being returned - does it actually contain more than one stop? What do the Debug.DrawLine calls from the vehicle show?

avatar image n8 · Mar 17, 2010 at 08:07 PM 0
Share

Hi. I am having a terrible time trying to figure this all out. I have path setup, and am trying to implement the unitysteer portion. Piecing together the script from above i keep getting numerous errors. the one that i cannot figure out is this: " The type or namespace name `AngryAntPathway' could not be found. Are you missing a using directive or an assembly reference?". As best as i know i am including the correct library to get this to work. any help would be greatly appreciated.

avatar image Ricardo · Mar 17, 2010 at 10:06 PM 0
Share

n8, you'll notice that AngryAntPathway is not compiling by default, as the UnitySteer distribution does not include Path. You should remove the "#if false" at the top and "#endif" at the bottom of the class file.

avatar image n8 · Mar 18, 2010 at 03:55 AM 0
Share

Awesome! Thanks, that got everything mostly working. One more quick question. I have a race scenario and I need my vehicle to cycle through multiple points. Is there an event that I can listen for to know when my vehicle has reached the destination in order to switch to the next destination? thanks in advance for any help you can offer?

Show more comments

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

1 Person is following this question.

avatar image

Related Questions

NPCs random movement 2 Answers

Attack Script problem please help 1 Answer

A* Pathfinding, destroying a path once it has reached its end 0 Answers

Determining rotation for collision avoidance? 3 Answers

Steering an AI vehicle to a waypoint using float of -1 to 1? 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