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
6
Question by e-bonneville · Mar 14, 2011 at 07:12 PM · aipathfindinggrid

How to write a basic pathfinding script

What are the basic principles involved in writing a pathfinding script? In my case, I'm confined to a hexagon grid, and want units to be able to move from one position to another on the grid.

If the grid is composed of separate gameObjects and each tile knows its neighbors, how would I be able to calculate the path from a starting position to the ending position taking into account blocked tiles?

Thanks for taking the time to answer this, Elliot Bonneville

Comment
Add comment · 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 Simon-O · Jan 29, 2014 at 10:22 PM 0
Share

FYI Have a look at this example it demonstrates the strengths and weaknesses of different pathfinding algorithms

5 Replies

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by Bunny83 · Mar 14, 2011 at 09:08 PM

For node based graphs or grids I would recommend A* (A star). It's maybe a bit advanced but it's one of the easiest and quickest algorithm and not that hard to understand. Almost every "simpler" algorithm will have problems at least if you have special cases like dead ends.
I can't post a full example because that would be a very long post and I don't have an A* implentation for Unity at the moment.

ps. A lot (if not all) RTS games use A* for the AI. It's a very very common algorithm. You should find tons of implementations and examples.

Hope that helps.

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 Thom Denick · Mar 15, 2011 at 12:09 AM 1
Share

Aron Granberg has a A* plug-in which is free for non-commercial projects: http://www.arongranberg.com/unity/a-pathfinding/

You can find more pathfinding solutions here: http://answers.unity3d.com/questions/1523/pathfinding-tools-in-unity

avatar image e-bonneville · Mar 15, 2011 at 01:21 AM 0
Share

Thanks a lot. I will look into A*, Bunny83.

avatar image
3

Answer by poncho · Mar 14, 2011 at 08:51 PM

well if you want a basic pathfinding, i would recommend that check your position and the distance to the objective, then check your neighbor position and its distance to the objective, compare the neighbors distance to see wich one is closer to the objective then move or change the current to the neighbor that had the less distance

if you want to get more complex and better algorithms you will need to check Operational Research, closest path.

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
avatar image
1

Answer by SriramGanesh.du · Feb 16, 2012 at 11:20 AM

I made a quick tutorial for those interested in learning how to setup a basic AI pathfinding using NavMeshes in unity 3.5

http://www.youtube.com/watch?v=TD11AzSQ0Ao

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
avatar image
0

Answer by NanoMath · Jan 11, 2013 at 08:36 PM

A* (AStar) Unity3D OpenSource (download My A* PathFinding OpenSource Project and open in Unity3D). Do Not Forget to read README.txt file ! Enjoy it !

Best Regards !

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
avatar image
0

Answer by ifonlyme1000 · Aug 31, 2020 at 03:35 PM

https://www.udemy.com/course/turn-based-strategy-game-development/

Pathfinding in action.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

RTS Grid and Pathfinding 2 Answers

Pathfinding unity 3 Answers

ai pathfinding project getting started scene problems 1 Answer

Does A* Pathfinding work on all 3 Axis's. 1 Answer

Grid-based path-finding, similar to Legend of Grimrock/Eye of the Beholder... 2 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