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

0 favourites
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • 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

  • 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.

  • 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.

  • 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.

  • here you go enjoy

  • mediafire.com

    (click to place the ball)

  • 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.

  • the capx does that if im not mistaken

  • 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.

  • Ash10500 thank you I will check this out later. Appreciate it.

  • Ash10500 This example did help me figure out how to get started, I tweaked it and figured out how to make it work with my game, thank you for your help.

    I am trying to figure out now how to throw to the player closest to a certain base. For example, I am wanting the player with the ball to throw to the player closest to second base by pushing 'W'. It seems to be one tricky thing after another with this baseball game...So far I have it where the player with the ball will turn and throw to second base, so it is partly working. Just now need to figure out how to use the closest too event for this. Any ideas on this?

  • Pick Nearest ? If at the same time as you throw the ball to 2nd base , you move the fielder nearest to 2B there - which is basically the same code, is this a good enough approximation ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here, let me know if you need any more help.

    mediafire.com

  • Just brainstorming:

    I would divide the play into parts (in the event sheet you could use groups for this)

    1 - ball gets thrown/player hits

    2 - ball is flying/ fielders walk

    3 - ball is with fielder/ fielder throws

    By disabling/enabling the groups depending on what part of the play is in action, you can have specific events/conditions for that part.

    This would probably make a huge difference in readability for your event-sheet as well..

    A game like this consists of many or even an enormous amount of conditions depending on how "realistic" you'd like to make it ..

  • As Baseball is largely cricket with the skill element removed (ducks) I'd advise spending as much time on the core bits as possible. I've written a lot of cricket Sims but the one that really worked was on the Amiga, I sold a lot of shareware copies of that. The reason was that it actually felt like you were playing cricket, not some quasi graphic simulation of it (the graphics were very basic but sufficient). The player (I think) sort of gets into a zen state where they imagine they are actually playing a real game. These games are very popular with people who'd like to be good at the sport but aren't (I love cricket but am rubbish at it, after 40 years I can mug through on wits, just )

    The core of the game is really what we call batting and bowling and I think you call batting and pitching (sorry I'm British ......). Get these right and your game will work. That's what players want to do - fielding almost doesn't matter. My shareware game had a very trivial implementation of fielding (actually you saw nothing except where the ball ended up on a mini scanner) and nobody ever cared about it. I probably wrote it in about 20 minutes. But I spent hours and hours making the batting and bowling feel approximate to the real thing.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)