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 Gintas_ · Feb 24, 2013 at 04:29 PM · aicharactersimpleenemies

following enemies simple AI problem

I'm using the most simple AI for my enemies, but it has some problems. Enemies follows the character and after some time they goes to one place. I don't know how to explain it, so I made a simple scene, here is the video(imagine spheres are enemies): http://img201.imageshack.us/img201/6026/e1jkgkfvdbucbsqnfrxmcn.mp4(sorry for poor quality). Here is the code:

     public GameObject characterObject;
     void Update()
     {
         transform.position = Vector3.MoveTowards(transform.position, characterObject.transform.position, 3 * Time.deltaTime);
     }

any ideas how can I avoid that? I would like to fix it without rigidbody. Hope someone will help :).

Comment
Add comment · Show 3
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 FL · Feb 24, 2013 at 04:45 PM 0
Share

I believe the best fix is to use rigidbody, make it kinematic. An other fix may requires a lot of work.

avatar image Golan2781 · Feb 24, 2013 at 06:58 PM 0
Share

Seeing how you are looking for an efficient way to do it, that really depends on what game you are trying to make. Physics/Collisions are very efficient, you'd need a very specialized solution to beat them.
So... what game are you trying to make?

avatar image Gintas_ · Feb 24, 2013 at 07:00 PM 0
Share

it's like top-down shooter, very similar to $$anonymous$$igore.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by nsxdavid · Feb 24, 2013 at 05:45 PM

There is no bug, per se. It is doing what you told it to do. Every enemy is trying to reach the same point, moving at the same speed. That point moves, but still they are all essentially going to always end up on top of each other.

To avoid it you need more more variables in the system. For example, varying speeds of enemies might help some. But beyond that, you probably want some sort of steering behavior to try and keep them apart.

You might want to check out UnitySteer on github for a solution.

Comment
Add comment · Show 3 · 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 Gintas_ · Feb 24, 2013 at 06:54 PM 0
Share

did I said it's a bug ;)? I know it's not, I just can't think the solution without using rigidbody. Game is for android devices, so I'm searching maybe more efficient way than rigidbody. What is UnitySteer, any related examples :)?

avatar image nsxdavid · Feb 24, 2013 at 08:50 PM 0
Share

UnitySteer are tools for making more intelligent behaving AI. Steering behavior. For example, one thing it can do is keep AI actors from getting too close to each other as they chase some goal (aka your player). Which is precisely what you are after, I think. Its free too.

avatar image Gintas_ · Mar 02, 2013 at 10:02 AM 0
Share

If you use UnitySteer, could you help a little bit here? I download examples but it can't find some required scripts. Where to get these scripts?

avatar image
1

Answer by fafase · Feb 24, 2013 at 07:05 PM

Most simple way would be to go with:

 public Transform player;
 public float speed;
 void Update(){
   transform.LookAt(player);
   transform.Translate(0,0,1*speed)
 }

If you feel like learning basic of NPC AI you can have a look there: http://unitygems.com/basic-ai-character/

Comment
Add comment · Show 16 · 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 Gintas_ · Feb 24, 2013 at 07:08 PM 0
Share

it's actually exactly the same code which I posted above. I need an efficient solution for problem which I showed in the video.

avatar image fafase · Feb 24, 2013 at 07:14 PM 0
Share

"They go to one place" do you mean when they start to get on top of each other? If so, it is because you are moving them with the transform. If you want them to stick individually, use the Character Controller and move them with it. (The link I provided has all about that)

avatar image Gintas_ · Feb 24, 2013 at 07:16 PM 0
Share

yes, I mean "they start to get on top of each other". But would character controller component be efficient for about 10-20 enemies in scene at the same time?

avatar image fafase · Feb 24, 2013 at 07:20 PM 0
Share

Yes. The other way would be to constantly check for distance between each object which then would get quite expensive while CC is all doing it for you. Actually, most game use CC and they go well with it.

If I were you (and I am not) I would try and see, if that is not doing it then you may think of another way but I am quite confident it will be fine.

avatar image Gintas_ · Feb 24, 2013 at 07:25 PM 0
Share

okay, I'm going to try it now...

Show more comments
avatar image
0

Answer by KingKongFu · Feb 24, 2013 at 07:40 PM

You could just stop them a bit away from the final destination but that would still keep them piling up one way is to check if there is something in front of the bot using ray trace and if there is stop the movement. That would not add much complexity to the game and keep overhead down to a minimum. I hope this help.

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 Gintas_ · Feb 24, 2013 at 07:51 PM 0
Share

I already thought about distance checking of closest enemy, but I'm not sure if game will look interesting if all enemies will be like "start stop start stop".

avatar image KingKongFu · Feb 24, 2013 at 10:25 PM 0
Share

well it seams to me that you want like a zombie mob thing so what I was thinking is that they basically stack up on each other so that would not look bad. They would just get in each others way.

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

13 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

Related Questions

AI navigating all 6 sides of a cube 0 Answers

Simple AI and Animation 2 Answers

How to get a velocity unit vector from a NavMeshAgent? 1 Answer

AI in Untiy, best practices 1 Answer

Pong game AI problem. 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