• 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 mecevit · Nov 08, 2011 at 02:21 PM · ai

AI: Organized attacks

Hi,

I am working on a sword game and having troubles with planning organized attacks.

Take a look this video captured from Assasins Creed. I want to achieve this kind of AI behaviour when multiple enemies need to attack one-single player.

I can not locate my enemies around my player. I have tried to calculate preferred-positions for enemies around the player, but somehow it didn't look good.

Can you forward me to helpful articles or explain the behaviour i should implement to my enemy units?

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 timsk · Nov 08, 2011 at 03:10 PM 1
Share

Looks like you're nearly on the right track. Studying the AI from that video, it seems like the AI marks someone to be the "active combatant" and everyone else keeps a certain distance from the player, and a certain distance from each other (thus for$$anonymous$$g a circle). Even when the player engages another enemy, the "active combatatant" doesn't seem to change straight away.

There is of course more to it than that, for instance, you do need to switch the active enemy in certain circumstances, how do you decide who the active enemy is? And of course many more questions.

Also, a few little bits are added there for quality, for example the enemies react when the player swings (even if they are not the person being swung at).

Your question does involve a specific question "I can not locate enemies around my player". You need to break this task down into more of questions like these and then tackle them 1 by 1.

Also, be aware. The $$anonymous$$m that designed and developed that AI have bucket loads of experience and skills on you, it's good to aim high, but be realistic ;).

Edit: Notice how you did get an answer to your one specific question there ;)

avatar image mecevit · Nov 08, 2011 at 10:33 PM 0
Share

@timsk your 2nd sentence just enlightened me. i was so confused between lines of codes. thank you very much.

i have implemented the main idea to position my enemies by applying steering force to seperate them if they are to close to eachother, while always keeping the offset distance to the player. I will need to make some fine-tunings, asap i will upload a video.

thanks again =)

avatar image timsk · Nov 09, 2011 at 02:28 PM 0
Share

would love to see the video, I love scripting AI :).

2 Replies

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

Answer by mecevit · Nov 11, 2011 at 10:55 AM

As promised, here is the video. I have implemented @timsk's idea. seperation vector still needs some work but.

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 timsk · Nov 11, 2011 at 11:17 AM 0
Share

Looking good! You've got the basics down to be honest, you need to tweak it here and there and add a few extra features (at the moment, no one is attacking). Also, it looks a bit strange when the player isn't moving and the enemies don't react, not moving in a fight usually makes the enemy make a move. Plenty of other stuff to think about too, keep on scripting ;).

avatar image NathanJSmith · May 24, 2018 at 01:45 PM 0
Share

Can you put the video on Youtube or paste the code in the answer? I can't view the video. Thanks.

avatar image
1

Answer by softrare · Nov 08, 2011 at 03:12 PM

I am going to assume you have the enemies in a list called "enemies". Then this should bring you forward:

int rad = 30; for (int i=0; i<enemies.Count;i++) {

     //summon the enemies around this central GameObject
     float radian = i * Mathf.PI/(enemies.Count/ 2);
     Vector3 ePosition = new Vector3(rad * Mathf.Cos(radian),transform.position.y , rad * Mathf.Sin(radian) );
     enemies[i].position = ePosition;
 }

Put this in a script on the player you want to surround. If it does not work, pls report back and show a screenshot of what you got. You could put in the Update() or in a function which is called when the main player moves. Also you'd probably want to replace the last line of code with something like this:

enemies[i].walkTo(ePosition);

So much for the positioning. To attack one at a time simply create an object that is designated to be filled by an enemy and designate it to a random enemy if it is empty. Set it to "null" again, if this particular enemy died and make it so that it designates another random enemy again to be the "acting" one. Let the acting one act, and the others rest :)

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 mecevit · Nov 08, 2011 at 10:36 PM 1
Share

@softrare thanks for interest. however my player is very dynamic and always in a moving mode. so if enemies take place in the order of their index in list, it would seem odd. they need to approach the player while keeping their facing angle to the player. just watch the game video carefully. enemies position in the circle always changes.

avatar image syclamoth · Nov 08, 2011 at 11:29 PM -1
Share

Wow, you really are impossible to please. It's not as simple a problem as you think it is!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Following the next item in an array 0 Answers

AI isn't looping (Javascript) 1 Answer

Steering Overcompesation 0 Answers

Ai pathing through a maze 3 Answers

Problems with raycast obstacle avoidance 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