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 TifaOng · Oct 23, 2013 at 01:34 AM · c#ai

AI positioning in soccer game

I am currently programming AI players for a soccer game. I want to ask what kind of algorithm should I use to create AI players that can find the best positions to block and steal the ball.

The game is in 2D

Thanks in advance.

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

Answer by DFledermaus · Oct 23, 2013 at 02:28 AM

In soccer the trick is the lines, the line from the player with the ball to the goal if they intend to attempt to score, or from one player to another if they intend to pass. Have each enemy player decide which is more likely based on player distance from the goal and from enemy players.

Then update the enemy player's AI script with a target direction toward one of these lines. Not the points at the end, you don't always want them running directly at the player for instance. They need to move to the nearest point on the line between the player and the player's expected objective.

This is an explanation of how to find that path.

And if you can, take the player's velocity into account, so use their present location multiplied by their speed per second multiplied by the number of seconds it would take the enemy player to get to that location, instead of simply their present location only.

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 TifaOng · Oct 23, 2013 at 03:03 AM 0
Share

Thanks for the info! I am beginning to understand how it works. Some of the questions, how do you position the AI along those lines? Vectors don't have positions. Secondly, the player's velocity, speed and time is for what?

avatar image DFledermaus · Oct 23, 2013 at 05:20 AM 1
Share

You'll need to tweak the formula I linked to in order to make it return the target ins$$anonymous$$d of the distance to the target, or look around for other formulas that might be more precisely what you need.

You'll also need to combine it with another target, such as the player's location, so the enemy player doesn't just move to intercept and stop. Scale between the two depending on how aggressive you want the enemy to be.

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

15 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Enemy AI C# 0 Answers

Another Raycast Issue. 0 Answers

stupid errors i can't figure out 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