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
1
Question by Ozale · Mar 21, 2011 at 12:12 AM · aipathfindingmazepacman

Maze Game Pathfinding AI

G'day guys,

I'm developing a maze-game (think Pacman, etc.) in Unity, and have now created a maze that can be navigated by the player, and now I am working on AI.

My AI has two 'modes' - 'Pursuit' and 'Patrol'. 'Patrol' is complete and I'm satisfied with it; the AI-Controlled character moves about the maze picking random directions, but of course doesn't double back the way it came (it would look absurd).

Now I'm developing 'Pursuit' mode. I've build a very rudimentary system, which you can see below, that uses the game's array-driven navigation to make the AI move north (if possible) if the player is indeed north of it, south if the player is south etc.

This works pretty well, to be honest, for its simplicity. But alas it is, of course, possible to 'trap' this simpleton AI by hiding in a position (such as a corner) where both horizontally and vertically it isn't possible to get closer to you. I tried (as you can see) to tell it to, in this situation, go to 'Patrol' mode for 1 'movement', but once it does this of course it sees the old 'corner' position as an attractive option.

I'm expecting that I'll have to take quite some time to study the A* algorithm and write my own Unity implementation (all links to the wiki script version are broken for some reason) as I know it's probably best to learn to do it myself, as so far - despite using these forums/questions to learn from other developers - I've avoided using other people's scripts as there is no benefit in using something I don't understand.

At any rate, I was wondering if anybody had any suggestions that might allow me to avoid writing a lengthy and (to me at least) complicated A* system?

function PursuitAI (){ playerRow = gridPlayerCharlie.rowIndex; playerCol = gridPlayerCharlie.colIndex;

     var randomDirection  = (Random.Range(1, 5));

     oldDirection = realBearing;

     if (playerRow > rowIndex && north == true){
         desiredBearing = 'North';
     } else if (playerRow < rowIndex && south == true){
         desiredBearing = 'South';
     } else if (playerCol > colIndex && east == true){
         desiredBearing = 'East';
     } else if (playerCol < colIndex && west == true){
         desiredBearing = 'West';
     } else {PatrolAI();}
 }

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
0

Answer by Eric5h5 · Mar 21, 2011 at 12:30 AM

A simple flood-fill algorithm would work. See the code in the project here.

Comment
Add comment · Show 4 · 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 Ozale · Mar 21, 2011 at 01:38 AM 0
Share

Isn't a flood-fill algorithm similar (or just a derivative) of A* pathfinding?

avatar image Ozale · Mar 21, 2011 at 01:42 AM 0
Share

PS: I'm reading your '$$anonymous$$anager' script, although having some difficulty wrapping my head around it.

avatar image Eric5h5 · Mar 21, 2011 at 04:53 AM 0
Share

See here for something on flood-fill: http://realtimecollisiondetection.net/blog/?p=83

avatar image Ozale · Mar 21, 2011 at 05:41 AM 0
Share

Yeah, looks like I'll need to write an algorithm. I considered using Aron Granberg's A* pathfinding, but the link is broken - his site appears to be down. I must admit, this is heavy stuff for me, so I'll take my time with it. For the moment I might reduce the distance at which the AI engages 'pursuit mode' to 2 'tiles' away, which will remove any chance of the player being able to get it snagged. This'll allow me to build a functional gameplay prototype so I can have that alpha-tested while I work on this pathfinding stuff. Shame the A* pathfinding script is down, I'd love to check it out.

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

Set AI Destination Setter target from Script 2 Answers

Patfinding cant change destination Target 0 Answers

A* or AStar Pathfinding doesnt work for me? 0 Answers

Can anyone recommend an A* hex grid pathfinding tutorial - or script? 1 Answer

Maze navigation 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