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 rockyourteeth · Aug 16, 2013 at 05:23 AM · pathfindingorder-of-executionpath-findingpathing

How to get actions in multiple instanced objects to occur in order

This is more of a question of strategy.

Basically, I'm trying to make a sort of path-finding system. There are "intersection" objects at each intersection, and they have a variable called "stepsToTarget". When I click, I lay down a target object, and each intersection object should set their "stepsToTarget" variable to a number. The one nearest the target will be "0", the ones next to that are "1", etc.

(Then, ideally, the player object would just look around for the intersection with the lowest number and walk toward that until it gets to the target)

So, if I have a map with 3x3 intersections, and I click on the bottom right intersection, it should look something like this:

4 | 3 | 2

3 | 2 | 1

2 | 1 | 0

So, I accomplished that by making a script for each intersection that basically says "Okay, look at each intersection around you. Find the one with the lowest number. Now set your number to that + 1.

This works great logically, except that I have to click multiple times to get it to work. The problem is that all of the intersections' scripts execute in some order, and they're all looking to their neighbors for their "stepsTotarget" number, but some of them haven't been set yet, which causes this one to be set wrong.

So, does anyone have any ideas on how to make sure they all get set correctly? I hope it makes sense. I can paste my code in if anyone really wants to see it, I just thought it wasn't necessary in this situation.

And I guess as a side-question, can anyone point me to the knowledge about what determines in what order scripts are executed? (I mean, one script over another. Not just within a single script)

Thanks in advance!

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
1

Answer by bubzy · Aug 16, 2013 at 06:29 AM

 int mapWidth = 5;
 int mapHeight = 5;
 void makeMap()
 {
 for (int y = 0; y < mapHeight; y++)
   {
   for (int x = 0; x < mapWidth ; x++)
     {
     //instantiate your object here
     //you can then assign the object a value based on the x,y values.
     //this will instantiate the objects in order, and allow you more control
     //after this you may want to look for the manhattan method of 
     //calculating heuristic values.
     //this method works OK, but doesn't allow you a lot of flexibility without 
     //the rest of the a* algorithm
     }
   }
 }
Comment
Add comment · Show 2 · 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 Jamora · Aug 16, 2013 at 07:39 AM 0
Share

I would've used a breadth first search, but this is probably a simpler way.

avatar image rockyourteeth · Aug 16, 2013 at 03:00 PM 0
Share

That's useful advice. I'll read up on that A* stuff.

But doesn't your method of instantiating them only work if a map only has one static target? If I'm creating a new target every time I click, then I'd have to destroy and re-instantiate them, wouldn't I? I guess that's not too terrible if it works...

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

17 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

Related Questions

A* Pathfinding issue with directly adjacent nodes. 1 Answer

Help with Path Finding in my game. 1 Answer

Pathfinding on multiple targets 1 Answer

Astar Pathfinding - do not use last visited node 1 Answer

A* nodes in the basic version of unity. 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