• 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 /
  • Help Room /
avatar image
0
Question by lhaggot · Sep 04, 2021 at 10:18 PM · transformpathfindingif-statementspathpathfollowing

How can I setup a AI Bot to Pathfind around my small map?

So, I have a small map for a mobile game made but I'm having a bit of trouble coming up with the concept of pathfinding around it. I have a player walk into my Store (the map) and create targets for different areas of the store. I want to create a line of code that will take into consideration the Players' current position, and the Target position and move to that spot. However, I have made specific other Transform game objects around the map for the Player to navigate to move around obstacles that might be in the way.

alt text

All of the BuyableObjects are the colorful places on the map as shown, each one has its own special Child called Buy Spot that has a transform placed right in front of the object so that the player can navigate to that if the object is the Players target.

The Walkways are empty game objects with Transforms attached to them. They are the in-between objects for the player to navigate to so that I can make sure they avoid walking directly through other objects to get to their target.

My code for going to the target is so far, this:

 public IEnumerator GoToTarget()
     {
         Transform[] BuySpots;
         BuySpots = new Transform[StoreObjects];
         for(int i = 0; i < StoreObjects; i++)
         {
             Transform LocalSpot = BuyableObjects.transform.GetChild(i).Find("BuySpot");
             BuySpots[i] = LocalSpot;
         }
 
         GameObject Target = Objects[Counter];
         Counter = Counter + 1;
 
         //Create Pathway
         List<Transform> Pathway = new List<Transform>();
         int PathwayTargets = 0;
 
         if(gameObject.transform.position != Target.transform.position)
         {
             PathwayTargets = PathwayTargets + 1;
 
             yield return null;
         }

Everything before the Create Pathway comment is just setting up the variables to access the Transforms. So, depending on where the player is and what their target is decided how many places they will have to pathfind to on the map and where those places on the map will be.

I'm just not sure how to create code that could work like that, without making hundreds of if statements that would direct the player.

Does anyone know of a concept I could use? Or maybe another easier way of doing things that don't involve this level of Transform and complexity?

capture.png (83.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

How to make an object follow a path when necessary but move forward when holding mouse button? 0 Answers

Hi, I'm working on a city traffic project My problem is that cars always   At each point of the path they come to the starting point of the track when starting the game While I want to move where they are placed along the designated path this is my code 0 Answers

If statement not getting called after Lerping a Scale 1 Answer

Doing an Update Function only once 1 Answer

File Path Confusion for Sharing an Image 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