# I need advice on best way to have fielders chase the ball?

Get help using Construct 2

### » Mon Jun 29, 2015 6:01 pm

I am going to be implementing some AI in a baseball game I am making. When the ball is hit, the closest fielder will run to get the ball. What is the best way to implement either pathfinding or some other way so only 1 fielder runs to the ball and that it is the closest one to the ball? I will figure out how to do it, just not sure the best way to go about starting this. Thanks for any guidance
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

### » Mon Jun 29, 2015 6:14 pm

It is quite complicated. You have a straight line which is the ball trajectory after hitting it and you want the shortest right angle distance to that line, but eliminating anything that isn't catchable (e.g. above about 7-8 feet off the ground). There are probably some maths equations online that will solve this.

You can probably break it up into approximations. Standard equations will generate the trajectory of the ball from the impact of bat on ball and you can calculate it every couple of metres or so, working out if the fielder (do the basemen chase the ball ? English !) can get to that point in the elapsed time.

The problem is a human instinctively knows whether they can catch or get a ball or not, or someone else is better placed to do so.

Having written several cricket simulators over the years (a similar hit bat with ball and fielders game popular in the UK and other countries) it is very difficult to realistically simulate a swinging bat versus a moving ball accurately. Baseball is worse because the bat is round. Generally you cheat Most games rely on lining up and timing to determine where the ball is hit. Accurately simulating a pitchers behaviour "trying to trap a batsman" is even worse.

The thing to do is make it fun. Stick Cricket for example is absolutely awful as an accurate simulation of cricket. But its fun.

Someone from India (play cricket a lot there) asked me about this professionally, how do you accurately simulate the effect of bat on ball ; I suggested they don't, make it approximate, make it fun.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

### » Tue Jun 30, 2015 11:51 pm

@paulscottrobson Yes this does sound quite complicated. What actions would I use for this? I'm just not quite sure where to even begin with this. Thanks for any further guidance.
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

### » Wed Jul 01, 2015 5:48 am

You can't really. It's mathematics.

The simplest way of doing it is probably to calculate where it ends up, then get the nearest fielder to that end point to move there, catching it if the ball is off the ground just before it lands when it rolls. This works quite well for cricket, but cricket is different in that a lot of shots are along the ground anyway, and it means a fielder cannot intercept the ball on its way to the target area.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

### » Wed Jul 01, 2015 5:59 pm

here you go enjoy
B
5
S
1
Posts: 60
Reputation: 495

### » Wed Jul 01, 2015 6:01 pm

Message: Ash10500 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
https://www.mediafire.com/?i1zx14n9zjo1io6

(click to place the ball)
B
5
S
1
Posts: 60
Reputation: 495

### » Wed Jul 01, 2015 6:54 pm

Depends how much accuracy you want. You may expect a fielder closer to the batter to stop the ball if it is hit right through them, and not to aim to move for the terminal position but some way between the two.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

### » Wed Jul 01, 2015 7:31 pm

the capx does that if im not mistaken
B
5
S
1
Posts: 60
Reputation: 495

### » Fri Jul 03, 2015 10:42 am

Sort of. Your game has no real ball trajectory, it is like my cricket game. I think personally it is sufficient for most games. The aim of a cricket or baseball game is to be fun to play, not realistic.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

### » Mon Jul 06, 2015 6:10 pm

@ash10500 thank you I will check this out later. Appreciate it.
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

Next