• 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
Question by IMTRIGGERHAPPY9 · Jul 15, 2011 at 08:25 PM · javascriptarrayaipathfindingbox

array of boxes

ok so here is my problem, i want to get from point A to point B. but the way i want to do it is with boxes. so say i have a 20x20 plane that is made up of boxes and the array goes from left to right and then down so box 1 would be 1x1 and to the right of that would be 1x2 and below 1x1 would be 2x1.

so say i start at 10x1 and want to get to 10x20(10x20 being point B) i want my algorithm to be smart and know what the boxes next to it are saying. so if we started at point A then our box would first look to the right of it(10x2) and if that spot was deemed walkable then it would then point the character that was on top of it to the box to its right. but if the box to the right(10x2) was not open then it would look down below it to 11x1 and see if that was open and then point that way. and it would go around in a circle till it found away that worked.

i am like brand new to unity coding, but have experience in c++ so i do know how to code, that being said unity is very unique and doesnt quite make sense completely yet. i have started some tutorials and am starting to get the hang of it, but i still dont have a clue how to make an array of boxes like i said. i would appreciate any help at all! but please teach it to me in a way you would teach like a 10 or 14 year old ha ha

PS sorry for it being so long i didnt know how to explain it other than the amount i toke

Comment

People who like this

0 Show 1
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 IMTRIGGERHAPPY9 · Jul 15, 2011 at 08:26 PM 0
Share

ps i have looked at the A* script so please dont refer me to that. my reason being that the a* requires it to be on each character, but i will have multiple characters on each box at a time so this would be a waste of ram.

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by DaveA · Jul 15, 2011 at 08:42 PM

You could make a two-dimensional array, the scripting reference and this forum has much to say about how to do that.

Why would it be a waste of ram? I may be misunderstanding what you are trying to do, but it seems you'd just be putting additional checks in your A* alg where it checks for availability. Each character could have it's own A* (maybe that's where the ram waste is?) but they could share a common 2d array and other structures, if that's a big concern. If it's really just 20x20 that's not too bad. If it were very big, I'd worry more.

Comment

People who like this

0 Show 6 · 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 IMTRIGGERHAPPY9 · Jul 15, 2011 at 08:53 PM 0
Share

it is a lot bigger my 20x20 thing was just an example and i am planning on having about 500 characters on the screen at one time. i dont want all of them having an A* algorithm on them when a lot of those characters will probable be in the same box, like 5 characters will all be trying to get to point B and be in box 1x4 i would want A* to calculate all 5 of them when i could have that single box tell all of them where to go. it saves a lot when you are dealing with higher numbers thank you for the very quick response though

avatar image IMTRIGGERHAPPY9 · Jul 15, 2011 at 08:53 PM 0
Share

correction ( i wouldnt want A*) sorry about that

avatar image IMTRIGGERHAPPY9 · Jul 15, 2011 at 08:55 PM 0
Share

and i wasn't planning on having an A* algorithm at all in my game

avatar image Waz · Jul 15, 2011 at 09:42 PM 0
Share

Well, you should. Your position is equivalent to "I want to add two integers, but I don't want to use the + operator". You can write your own Dijkstras shortest-path algorithm if you like - it's only about 20 lines of code.

Also calculate how much RAM you're talking about. 20MB is hardly anything these days.

avatar image IMTRIGGERHAPPY9 · Jul 15, 2011 at 10:17 PM 0
Share

ok here is my problem completely fleshed out. i am trying to optimize this game for the iphone so any bit of optimization i can get helps seeing how i am already trying to render the entire thing in 3d. and i have had a lot of problems with A* when it tries to recalculate its path... so i want a predefined path for each character cause this will be a tower defense game so i want those calculations to be spot on and lightning fast. the A* doesnt give me that from what i have seen. and this solution was kinda thought up by me so i would like to make a game that is completely my thought not somebody else.

Show more comments
avatar image

Answer by Waz · Jul 16, 2011 at 08:57 PM

Sounds like what you want is Dijkstra's algorithm:

  • only needs to be recalculated if obstacles are added that change the path

  • all travellers use the one data set

  • very little memory required

  • very fast to calculate

A* is just a variant that is faster for a single traveller and handles multiple destinations. It's hardly any different though, so I suspect any concern you have is about some particular implementation of the algorithm.

Comment

People who like this

0 Show 0 · 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.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

JS: Display Array contents in a Box 0 Answers

Pathfinding. Does not "walk" on every tile. 1 Answer

Building an array help 2 Answers

Noonb array question - Boolean makes a script activate for all elements in an array. Problem is the only element that gets the script activated is the first one. 1 Answer

A* optimization and path help 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