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 dyankov · Oct 27, 2013 at 03:54 PM · aipathfindingrpgfollow path

Super basic enemy pathfinding AI

So far I have a simple test scene for an RPG game with a player in the center and enemies spawning around him. The player and the enemies are using Character Controller component in order to control how tight they can bunch together. The enemies have a script which makes them move towards the player. When the player starts running around all enemies start following and they tend to form a tight crowd and everything is fine so far.

The problem comes when the player stops and the enemies that are bunched together need to surround him. To do that, they have to stop following the straight line path and move a little bit around in order to find space around the player.

I can think of a number of solutions, one of which uses colliders or ray casting in order to find out if the path to the player is obstructed, but I have the feeling it's not a very elegant solution. I just wanted to hear some other opinions, I'm sure there is a simpler way/algorithm/logic to make the enemies surround the player.

I'm not really expecting the enemies to be super clever, I want to keep it light and simple, because I'm targeting mobile devices. Any ideas are appreciated!

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
Best Answer

Answer by Velo222 · Oct 27, 2013 at 05:12 PM

Hey just throwing out a couple ideas here. I'm currently working on an RTS and in order for my units to "attack" an enemy, they have to surround the enemy as well. The way I'm doing it currently, is I'm using Aron Granberg's A* pathfinding, and when a unit gets a certain distance from the enemy (I keep track of the distance to the enemy target about every .5 seconds) the unit then stops and updates the grid beneath its collider or bounds to be "unwalkable".

Then I also have my units calling a path every .2-.6 seconds while they're attacking, and if the pathfinder sees that a grid cell is unwalkable, it paths around it. Thus, my units path/steer around units that are "attacking" the enemy already. The downside to this is that the grid cells are not fine-grain in resolution, so I get some units "sliding" around units on some occasions -- as the path isn't as precise as I'd like it to be for performance reasons.

The other idea I was thinking of, is to store say 4-5 points around your unit (maybe even use an empty game object), and have your units go directly to those points. Then when one point gets "filled", mark it as taken, so the other units will only try to fill the points that are left. I'm not quite sure how you could do this, but maybe using raycasts/colliders/local coordinates etc it might be possible.

Overall good luck and I hope you find a solution.

Comment
Add comment · Show 1 · 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 dyankov · Oct 28, 2013 at 12:29 AM 0
Share

Thanks for your answer. Actually before I ask this question I tried out A* and it seemed way too complicated for my needs and I couldn't get it to work properly. Then I did some research, watched a few youtube videos to see what it can do and it seems like it's the best choice for RTS and TD kind of games. So I've been playing with it for the past 6 hours or so and the result that I'm getting is encouraging.

It turns out the best way to manage big crowds is to use the Alternative Paths modifier script (comes with A*). Just put it on the enemies and don't do anything with the grid.

I will definitely spend a couple of days playing with this cool library.

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

16 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

Related Questions

A* pathfinding - how to put penalty below a character 0 Answers

Pathfinding for RPG games 2 Answers

NavMeshAgent doesn't face to it's destination in close distance! 1 Answer

Restricting NavMesh path finding directions 1 Answer

How to implement A* to have an AI trying to reach the player 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