playMaker

Author Topic: Sports AI  (Read 5063 times)

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Sports AI
« on: November 29, 2013, 04:11:12 AM »
I am very new to PlayMaker, and I am wondering if PlayMaker can make Sports AI, such as football AI. If yes, can you please share your idea on what kind of FSMs should I use?

An overview of the football game, 2 players and 1 goalkeeper. AI needs to pass and shoot the ball to the goal. This is an iOS app, so it uses touch screens to move players.

Thanks a lot. I really appreciate if you can help me because this is very urgent for my project.
« Last Edit: November 29, 2013, 04:22:58 AM by TifaOng »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports AI
« Reply #1 on: November 29, 2013, 05:17:27 AM »
Hi,

Yes, PlayMaker can do this, but if you are new to PlayMaker and Unity, I would suggest you take the tie to learn it properly, because this kind of AI is quite something to design actually, Playmaker will make it a lot easier to implement, but you will still need to come up with the idea and implementation.

 Typically, I would approach such problem doing the following. I would give much AI responsability to the ball itself, the ball would scan for which player is the closest to the goal which is closest to me and make decision based on this to call a player to pick the ball and kick it into the direction of the other or the goal.

 In all cases, this will be very much experimental and a trial error process. do you have alread some documentation on footbal AI technics and tricks? I would start here.

Bye,

 Jean

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Sports AI
« Reply #2 on: December 01, 2013, 09:01:40 PM »
Hi Jean,

I am fairly experienced in Unity with scripting and now learning to use PlayMaker.
I also wanted to know how to use scripting with PlayMaker, so far the tutorials I have watched do not touch scripting. I already have custom actions for kick,pass and dribble.

In your second paragraph, you mean the player closest to the opponent's goal will chase the ball and kick to the goal?

I have some idea on how to program my AIs movements,
  • Start kick off. Get the ball and pass to another AI.
  • The whole team moves forward if possesses the ball. (Attack)
  • Pass the ball if opponent is in front.
  • Kick to goal if near to goal and opponent is not in shooting line.
  • Move back to it's own goal if opponent has the ball (defend)
  • If AI is near to opponent with ball, AI will try to steal the ball.
  • AI who is closest to the ball will chase the ball.

What do you think about my implementation?
I also wanted to know how to implement this in PlayMaker, in states. Give 1 example for 1 of the implementation is more than enough.

Your help is greatly appreciated.
« Last Edit: December 01, 2013, 09:31:21 PM by TifaOng »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports AI
« Reply #3 on: December 02, 2013, 03:58:56 AM »
Hi,

 For this you need few things:

-- create a series of global events like

"TEAM A ATTACK"
"TEAM A DEFEND"
"PLAYER HAS BALL"

you can pass variables with these events, for example the player name that has the ball

and then, based on the ball situation, you broadcast these events to your players, so when a player from team 1 has the ball, you should fire "TEAM A ATTACK" to everyone and they will then respond in their own way.

 each player would respond to these events, do further checks on their situation, who has the ball, their situation compare to the ball and the goal and promote themselves as likely to defend or attack properly. For this, I would use ArrayMaker

https://hutonggames.fogbugz.com/default.asp?W715

you could sort your teams in order of the closest to the ball or strategice points and the AI would simply fire a "CATCH BALL" to the first few players on top of that list.

Also, make use of triggers, they will help you define logic easily. for example each player should have a radius of reach for the ball, and typically this will be a lot more performant if you use triggers for this, the ball itself should have this trigger as well, so that it can promote players to know they are within ball reach.

 All in all ( I got your pm), 4 days to do that is totally unrealistic... I am sorry. You can get something to work, but doing a footbal AI is actually very complex, and just implement the football rules is big deal. So your best bet is to define the simplest approach to have something looking like a ball game, then you can build up on this, but to get something done in 4 days, you need to define your specifications very well, and also cut down a maximum of uncessary behaviors and bring it down to the bear minimum. Typically, when in such tight deadline, I always try to achieve something workable asap, and then cleanup add more features. So typically here, I would first make sure I can have a player that knows how to seek the ball, run towards the goal and kick into the goal. This is your first major task, then you can build up on this.

Bye,

 Jean

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Sports AI
« Reply #4 on: December 02, 2013, 04:30:52 AM »
Hi Jean,

I agree 4 days is crazy. So what I plan to do is, at least the AIs can run, pass and kick the ball.

Listening to you, my minimum FSM will be seek the ball, run towards the goal and kick the ball. I want to ask you about the FSM. I have created a simple FSM at game start. Am I doing them correctly? It's attached.

Some questions,
1. Is my looping for the FSM correct?
2. How to access variables in existing scripts into PlayMaker?
3. If 1 transition is triggered by several different states, what should I do? For example, To run towards the ball can happen in state GameStart, NoBallOwner, and OpponentHasBall.
4. I already have existing project with EasyTouch, defending AI (without any plugin) and lots of other scripts. Now I added in PlayMaker, will this affect my project?

Thanks a lot, Jean!
If possible, I would like to have your Skype ID. I am really scared I cannot make it *sob*
« Last Edit: December 02, 2013, 04:45:44 AM by TifaOng »

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Sports AI
« Reply #5 on: December 02, 2013, 04:38:56 AM »
Do you have any sample projects/tutorials that utilize AIs? Preferably with scripts.
I found tutorials by BadSeedGames in Youtube, but it's not what I want.

Thanks alot!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports AI
« Reply #6 on: December 02, 2013, 04:48:07 AM »
Hi,

 I don't have any AI stuff that would be useful for your case unfortunatly. But I have a ball player package that could be useful for you.

http://hutonggames.com/playmakerforum/index.php?topic=4911.msg23391#msg23391

 Bye,

Jean

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Sports AI
« Reply #7 on: January 07, 2014, 05:19:46 AM »
Hi Jean,

I was getting back to AI after doing other stuff for my project.
Looking back at your answers, I have a few questions:

1. How to assign custom actions when enters a state?
2. I don't know how to use ArrayMaker, any tutorials on how to use? I don't understand about hastables and such.
3. Get variable value from scripting C# to FSMs, and vice versa.

Now my game is almost complete except the AI. I have thought all of the states with events the AI will enter.

Idle - Before Game Starts, before Kick Off.
Attack - Kick, Pass, Move towards goal, Dribble the ball, Avoid enemies.
Defend - Blocking, Tackling, Moving to block positions, moving towards enemy to tackle, Get the ball.

According to you using ArrayMaker, let's say,
Opponent has the ball, global event "AI DEFEND" is called, in AI DEFEND there are arrays of actions for AI to choose based on their current situation, like distance to the ball, distance to ball's owner, etc.? How does it work?

Can I use PlayMaker to make each custom action intelligent? For example, when kicking, it's kicking towards the goal area without goalkeeper. When enemies coming closer, AI runs faster or changes direction.

Thank you in advance!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sports AI
« Reply #8 on: January 10, 2014, 08:11:30 AM »
Hi,

 You don't assign custom actions to states, you simply use custom actions like any regular actions by picking it up from the Action browser and use it in a state. Maybe I am missing your point here, if that's the case, can you rephrase?

I don't have any ArrayMaker tutorial unfortunatly... I know how important it is, but  never found the time to do a tutorial series, basically your best bet is to study the samples provided and ask questions.

on c#/PlayMaker, please make some search on this forum it has lot's of threads on the topic, I do want to start creating a wiki page on this, so it's coming soon as a proper reference page on the wiki.

ArrayMaker is not a AI Behavior tree, it's only one building block that can help you achieve an AI system within PlayMaker. So no ArrayMaker will not give you that raw power of taking decisions based on parameters, for this you^ll have to do it as Fsms. That's possible and ArrayMaker will come into paly by letting you store lists of references to actions, but not actually the actions logic or behavior themselves. ArrayMaker only store references to variables such as strings, ints, gameobjects etc etc.

So in your case, you really need to look one level up and design your AI using FSM logics, states and events.

Also, Custom Action are c# scripts aimed at providing a very specific feature. So if you have c# experience you can write actions to help you implement your AI, but they will unlikely be "Footballer actions" in a way.

bye,

 Jean