Wednesday, 9 April 2014
Well Hello Mr Euler
When the timestep is very small and constant, this error is negligible. However, in computer games we can not guarantee the uniformity of the time step very well and, for most real objects, acceleration is not constant.
For something like the ball, which we want to behave pretty realistically as a physical object, it's probably a good idea to use a better integration method. If you are interested in the technical details, google "Verlet" and "RK4."
Anyway, for a game as simple (relatively) as Senseless Soccer, the Euler method is *almost* good enough. But you do get the odd visible hint of its shortcomings ever now and then due to the frame rate/time step measurement fluctuating for whatever reason. It manifests in the form of players running through the ball, the ball looking like it just teleported and bouncing off the posts too late or too early etc.. So lets implement a slightly more robust method for the ball.
Contrary to how most of the online tutorials come across, it's quite simple!! To smooth out the errors we simply take the velocities across 2 time steps, and average them to get a better estimation of what the current position should be.
The other methods average the values across a larger sample for even greater accuracy, but for our purposes this improved Euler should be fine. It may be some sort of psychological confirmation bias, but I think the ball looks more realistic already!
Incidentally, for the movement of the players we stick to simple Euler integration (of course the other methods would work fine too, but just aren't necessary). This is because the players always move with a constant velocity. There is no acceleration involved. It would be possible to implement a game where the players do have an acceleration component (so they couldn't change direction or stop immediately) but if you imagine the space ship in Asteroids as a player, you can see how infuriating that gameplay mechanism would be for a footy game like this!
Monday, 7 April 2014
Sunday, 6 April 2014
Quirks
One of the quirks of sensible soccer is that the player can only run in eight directions. This was a necessary mechanic back in the day due to the joysticks and gamepads being strictly 8-directional.Believe it or not, the modern style FIFA games worked pretty much the same way until quite recently (you can see them making a big deal out of "360 degree movement" in their ads) where they take advantage of the analogue "thumbsticks" on modern controllers.
Such a system wouldn't really work with a retro style sprite based game, as you'd have to have either a huge amount of sprites to cater for small differences in the angle of movement, strictly top-down sprites that can be rotated by the game, or ridiculous looking players who look in a slightly different direction to where they're headed.
So we're sticking with the simple sprite-based 8 directional movement scheme. It'll be slightly unrealistic for players like Rio Ferdinand, who only seems to be able to move in 4 directions these days, but what can ya do.
This does throw up a few quirks though. For example, with the movement of the AI players, you can't simply calculate the best direction to run in and update it every frame as this results in a very unrealistic zig-zag path as they attempt to reach their target.
[note there is more complexity to this when you consider static vs moving targets but we'll simplify it for the sake of explanation]
So to get a relatively realistic behavior that mirrors how humans use the controller, we calculate the heading to the target, round it to the nearest 45 degrees and set the player off on his merry little way. Obviously, if the target didn't just happen to lie on a 45 degree angle, he'll never actually reach it and the whole thing will fall apart. To counter this, we add a check to compare the distance from the target each frame. If the new distance from the target is larger than the last distance, this is a good time to recalculate the heading to the nearest 45 degrees. This *roughly* simulates how a human player would manipulate the controller to get where he wants to go.
This is an extremely simple solution to what is a huge field in game design (path finding etc) but it's interesting nonetheless and should be a good enough solution for our purposes.
Interestingly, the original sensi solved this problem with a complete and utter cheat. Its computer controlled players are not restricted to the 8-directional movement. It's not so galling visually when the computer does it, but there was always a subconscious "hmm that's not quite right" factor without knowing exactly what was up. If you go back and play or watch it now, it's quite obvious when you know what's happening.
Who knows, perhaps there are other reasons for the "cheat" that will force us to adopt this strategy later on. Living and learning!
Wednesday, 2 April 2014
Mindful Passing
When a player grabs possession, he has a few decisions to make. One of them is if there is a good pass available. The first step is to gather all the players in a possible receiving position. The mechanics of this kind of game means that the player is always moving when he has possession and must pass in the general direction he is moving. It's only fair the AI does the same.
So the small circle represents his short passing range and the large circle represents his long pass range. Any team mates within these circles will be considered as a possible passing target. Of course, if the player is under pressure and no passes are available, he'll have the option of hoofing the ball upfield blindly. So for Man Utd, the circles are essentially redundant.
I've zoomed way out so you can see what's going on:
So the small circle represents his short passing range and the large circle represents his long pass range. Any team mates within these circles will be considered as a possible passing target. Of course, if the player is under pressure and no passes are available, he'll have the option of hoofing the ball upfield blindly. So for Man Utd, the circles are essentially redundant.
I've zoomed way out so you can see what's going on:
Subscribe to:
Posts (Atom)



