playMaker

Author Topic: Soccer Game AI[SOLVED]  (Read 8111 times)

SpacialPumpkin

  • Playmaker Newbie
  • *
  • Posts: 14
Soccer Game AI[SOLVED]
« on: September 08, 2013, 03:00:30 PM »
Hi! I'm making a soccer game and I am trying to get the enemy AI to calculate and go to the best possible position from the ball and the goal in order to score a goal using pathfinding. I'm using the A* custom actions also. How can I achieve this with playmaker?

I attached an example picture of what I'm trying to do.

« Last Edit: September 18, 2013, 02:17:03 AM by jeanfabre »

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: Soccer Game AI
« Reply #1 on: September 08, 2013, 11:03:54 PM »
That would depend on a lot of different variables like Is this Spot Guarded by another Player, Am I guarded, How Much time is left on the clock, How far can i kick, would depend on all different things that you have set, up a good bit of these would work off Bools, for True and False, but also knowing what areas to move to as well with AStar.

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: Soccer Game AI
« Reply #2 on: September 09, 2013, 04:41:08 AM »
Beside what Saputo already mentioned,
here is a simple approach to give you a headstart. This will not work in realtime but maybe it brings up some ideas:

Try to find the fixed points and the obstacles. fixed points are:
1. the goal (fix in time and space)
2. the ball (fixed at one point at a particular time)
3. the player (fixed at one point at a particular time)

Now you can do spherecasts from the goal to the ball and check for obstacles.
if the way is free you have a point at the ball where it have to be hit by the player to be shot into the goal. By the way you will also collect the distance between goal and ball and multiply it to get the power of the shot.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Soccer Game AI
« Reply #3 on: September 09, 2013, 05:13:30 AM »
Hi,

 One way of doing this would be the following:

in your goal, have a dummy gameObject that always look at the ball. Extract from this its direction ( the looking direction) and normalize that direction, it will give you a vector that represent the direction form the goal to the ball. and because it's normalized it's easy to work with now:

 1: get the ball position
2: add to this ball position the goal/ball direction computed above, multiplied by the distance you want from the ball ( say 2)

in effect, this will give you the position of the player, it will be 2 unit before the ball, straight aligned with the goal ( like your picture)

does that make sense?

bye,

 Jean

SpacialPumpkin

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Soccer Game AI
« Reply #4 on: September 09, 2013, 09:32:46 PM »
Hi,

 One way of doing this would be the following:

in your goal, have a dummy gameObject that always look at the ball. Extract from this its direction ( the looking direction) and normalize that direction, it will give you a vector that represent the direction form the goal to the ball. and because it's normalized it's easy to work with now:

 1: get the ball position
2: add to this ball position the goal/ball direction computed above, multiplied by the distance you want from the ball ( say 2)

in effect, this will give you the position of the player, it will be 2 unit before the ball, straight aligned with the goal ( like your picture)

does that make sense?

bye,

 Jean

What action should I use to get the looking direction of the Dummy Object?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Soccer Game AI
« Reply #5 on: September 10, 2013, 01:25:43 AM »
Hi,

 Use "transform direction" action. And define the axis you want, for example, in your case, I think it would be vector 0,0,1, so that the direction represent the "z axis" of your dummy gameobject that is looking at the ball.

 Bye,

 Jean

SpacialPumpkin

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Soccer Game AI
« Reply #6 on: September 10, 2013, 11:55:05 PM »
Hi,

 Use "transform direction" action. And define the axis you want, for example, in your case, I think it would be vector 0,0,1, so that the direction represent the "z axis" of your dummy gameobject that is looking at the ball.

 Bye,

 Jean

Okay.. I got it working about halfway. I got the end result of your instructions to be right on the ball, but when I multiply it by 2 units, the position is moved to the wrong place, it goes to the side of the ball and not behind it, so the player moves to the side of the ball and doesnt end up going behind the ball to kick it.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Soccer Game AI
« Reply #7 on: September 11, 2013, 02:41:19 AM »
Hi,

 could you make a drawing to show where you end up? is the end point ( when you multiply it) properly aligned, that is it forms a straight line Goal-Ball-EndPoint?

bye,

 Jean

SpacialPumpkin

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Soccer Game AI
« Reply #8 on: September 11, 2013, 03:44:22 PM »
Hi,

 could you make a drawing to show where you end up? is the end point ( when you multiply it) properly aligned, that is it forms a straight line Goal-Ball-EndPoint?

bye,

 Jean

This is where it ends up when multiplied.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Soccer Game AI
« Reply #9 on: September 13, 2013, 03:48:16 AM »
Hi,

 Ok, Please find a workign sample doing just that. Tell me if it all make sense.

bye,

 Jean

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: Soccer Game AI
« Reply #10 on: September 13, 2013, 10:34:21 AM »
You might want to check out Dino Dini's GDC talk about making the classic Football game Kick Off! He talks about how he got the AI playing against each other first before implimenting player control etc...

Either way, it's a pretty good watch :)

http://www.gdcvault.com/play/1019341/Classic-Game-Postmortem-Kick
« Last Edit: September 16, 2013, 06:17:52 PM by 4ppleseed »

SpacialPumpkin

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Soccer Game AI
« Reply #11 on: September 17, 2013, 06:44:54 PM »
Hi,

 Ok, Please find a workign sample doing just that. Tell me if it all make sense.

bye,

 Jean

Thanks!!