Friday 17 December 2010

An unexploited (out)field

Since the beginning of video gaming, baseball has always received some attention. The sport itself is basically the most suitable to implement an enjoyable experience for users. You pitch, some one swings and if the time is right, he hits the ball and run the bases.
Without bothering about baserunning or other more complex aspects of the game, baseball was amongst the first sports to be brought to the arcades in the 70s.

The beginning of the baseball videogaming era was made of pixels, unexisting fielding and it was still entertaining
But, how do baseball simulations deal with the always growing demand for accurate physics in games nowadays? And what about actual baseball aspects like outfield assists or pick-offs?
The best baseball game so far is MVP Baseball 05 from EA Sports, dated back to 2005. It featured the MLB license, a graphically poor interface and menus but an amazing difficulty level calibration and it came up with unique amusement for baseball maniacs, who still play the game.
The thing I have always loved about that game is that it embodies at perfection the real entertainment about baseball: hitting the ball. Depending only on the timing, you could end up with a Home Run or with a blooper, or with a groundball or with a line drive. This shattered randomness in a sporting simulation, and considering that often baseball is about great players struggling with unexplicable slumps, or viceversa, it made the game feel real, maybe for the very first time.

A Dodger missing the ball. He swung early, and you can say it by looking at the position of the bat compared with the green/yellow contact zone.
The overall experience with MVP Baseball 05 was addictive. To take your franchise to the World Series you really to work out every count, to adjust your batting order, to know all the rival pitchers. On the other side of the ball, even if the depth wasn't comparable with the one required to hit, the pitching worked well, by letting you select the pitch type you wanted to use, the location and employing the usual accuracy/power bar which had to be filled to a certain measure twice.

The pitching gauge used in MVP 05. Since the hitter is a National, I don't think he'll get it!
But, was the physics model accurate in the EA Sports game? No, it wasn't.
What was the difference between chasing an high fastball and a low changeup? None. Basically because you don't decide the height of your swing. Even if the game actually interpret every swing as something different according to the timing, you'll end up realizing what are the pitches that are most suitable to you, recognizing them and blast only them over the fences. I used to love changeballs, someone used to maybe keen on curveballs, someone else maybe on sliders. Tha fact is that, regardles of who your hitter is, you don't change your tastes. I made Ichiro look like a .100 guy, whereas I broke any record about triples with Juan Pierre, simply because the japanes has a specific and uncommon swing animation.
MVP needed to diversify a bit the hitting mechanics to be aligible for best sport simulation ever, on every system.

But, let's take a step back and think about how a pitch is thrown and how a ball is hit.
The baseball, like the one we see above, is thrown from a certain position (release point expressed in terms of a vector x-y-z) according to pitcher's pitch dynamics and features. Cliff Lee has a different release point than Roy Halladay or Felix Hernandez.
It has an initial speed, which is the one revealed by measuring instruments on the field, which varies, at MLB level, from 50 or 60 to 107 mph. This speed needs to be divided into a velocity vector (x-y-z) which is calculated according to the release point.
Then, it also has a backspin (top spin) or/and a sidespin, given by the pitcher, who is unlikely to throw the ball perfectly still (unless he is Tim Wakefield or one of those knuckleballers).
So, we got 8 variables coming in: vertical angle, horizontal angle, speed, backspin, sidespin and the coordinates of the release point, which usually doesn't get any lower than 80 % of the pitcher height and not lateral to the mound.
In time = 0 we can then have the velocity vector, let's call it V0.
The ball is, in air, trapped between two different air flows, one above it and one underneath. These are regulated by the spin set by the pitch. To calculate the trajectory of a baseball for each time frame, we need to calculate the velocity vectors V1, V2, Vx and then the positions, call them P1, P2, Px.
To do so, we need to have the acceleration vector (in x-y-z) for drag force (gravity), growing when the ball loses speed, and for  lift force, the Magnus effect injected by the ball spins, which carry the ball towards a certain spot.
In this big pan with all our variables and forces coming in, we need to put temperature, the ball circumference, the air density (Coors Field anyone?).
What all games have done so far is to let the player select the type of pitch to throw, integrate its trajectory with the release point and the target he set, and calculate the positions. Now, MVP Baseball 05 looks a bit lazy...

I spent the last couple of weeks (let's say ten days) studying a spreadsheet by Prof. Alan Nathan of the University of Illinois, and trying to make a physics engine out of it. Would you believe that the results I got were more brilliant and much more realistic than the one EA had with the MVP engine? I was able to replicate fastballs, curveballs, sinkers, sliders, and test what happens if you allow incredibly huge amounts of spin to be applied to the ball (alienballs).


Is it really in the game?
So, we spotted another of an infinite list of fakes with which companies fill their games, but there is something more. What about batting? We left that speech about having a timed contact but not a technical one...
Well, if you know where the ball is going to be when the bat is hitting it, and you know the actual velocity vector associated to it, you can just flip the velocity component for the acis normal to the strike zone and obtain a rebound which does not alterate the trajectory.
Let's say we want to add the feature that the batter user can choose an height for his swing. It is enough to trap the bat into a bounding box and rotate it along its axis in the direction of the ball, to achieve a realistic collision detection, and then recalculate the trajectory finding the impulse applied to the ball by the batter. Now I'm getting confusing, but the principle is easy to understand, and to implement.
Nonetheless, we would end up with a fine realistic game, where all the measures are calculated in high fidelty and reflect their actual counterparts.

A ball perfectly hit. That's what happens all the time in MVP baseball, far from reality.
There is still one question to be answered. Why companies keep on delivering poor baseball games, so that we have to stick with MVP? I'm not so vain to say that I'm better than them or that I have a better understanding of baseball than their consultants. So, there must be another reason.
The answer is quite simple. Do you remember the first picture I shown in this post? That is the answer. People wants to hit the ball, to run the bases, to slide to save a triple, to assist from the outfield, to strike you out. They only think they want a precise simulation, but they don't. They just want to get back to the backyard with their father and throw the ball or receive with the glove.
At EA they wanted to deliver an entertaining game, fake it was realistic and make some cash. The last thing was not achieved, but the first two were a success. I will never be grateful enough to them for this, but I also would like to analyze the impact of a real simulation on the amusement mechanics. There will be time for this, I hope.

Thursday 11 November 2010

Multiple transformations in OpenGL

I bet a lot of you remembers “SuperOff-Road”, magnificient game for 8 and 16-bit consoles, in which you were driving Jeeps over a track. It was rendered from the top view, meaning that you were forced to see the whole track in third person. Your car used to accelerate with the D-pad up arrow (or a button, I can't remeber anything) and steer with the left and right ones.
The sprite was rotated and then translated following the newly created axis. Same story for the next frame. We were used to steer in a much simpler way at the time (I was maybe 7 when I played the first time and I hadn't played 'Super sprint'), so the new control system took a lot to be mastered, but was much much more actual. The game was fun, the multiplayer was a blast, the satisfaction reached new highs for the racing game genre.
How can we do it in an openGL environment?
We have a car seen from the top. We want to rotate it and translate it. Trivial. Not in OpenGL, that's why I'm writing this entry.
OpenGL works with an axis-oriented system, which means you'll be drawing shapes after having determined where their center is located. In case of multiple transformations, we first rotate the axis and then translate it, before drawing the car. The whole code is encapsulated between push and pop, to restrict the movement to that specific car.

glPushMatrix();
    glTranslatef(0,y,0.0);
    glRotatef(angle,0,0,1.0);
    drawCar():
glPopMatrix();

This way, unfortunately, the translation is from the center of the screen, not around our new car axis, which means the movement is not the actual one.
Before the push, for each frame, we have the axis centered back into the orygin, and that implies our translation will be calculated on that and not on the new axis.
Rotation is in this case correct, because happens after the axis has been translated.

To have the axis coming to the push exactly the same as the one after the car drawing, we have two ways of proceeding: apply an inverse transformation (much more painful than what you might think) or apply trigonometry.
In fact, the translation from the screen centered axis (in 0,0) to the new car axis can be defined in terms of cosin or sin. Imagine to translate your axis from the original one to the new one for each frame. This distance will be a vector of length l, whose x and y components are dx and dy, following the angle alpha you provide for rotation.

dx = sin(alpha) * speed                                             dy = cos(alpha) * speed

speed is l based on each frame. If in F0 the car is in (0,0) and in F1 it is in (0,1), this means that speed = 1.
So, we have to simply pass dx and dy instead of 0 and y to the translation, to have it happening in the new axis based on the car position.

glTranslatef(dx,dy,0.0);

Just remember to convert the angle from degrees to radius since openGl uses radius!
A solution like this is not present on the Internet, at least at this simple level, as far as I know, so I hope you find it useful. I know it's not very well documented, but I'll be updating it as well as granting answers to who wants to ask something about it, provided I can answer properly...

Wednesday 13 October 2010

The final adventure

During the last days a possible way to understand operating with pointers has messed up my mind. I need a little break, I'll think about something sweeter.
An orchestra. Hundreds of instruments playing the same song, coordinated brilliantly but with a lot of spare skills. That's because great solo players do not need an orchestra to be famous, they perform on their own, someone will go and listen to them anyway, paying.

A cuople of days ago this article http://www.gamecareerguide.com/features/898/game_narrative_review_shadow_of_.php caught my sight. It explains how Shadow of the Colossus plays a fundamental role in defining new play mechanics for adventure. To put it down clearly, the plot is not unveiled through the usual cut scenes or dialogues, but through the game appearance. Music, character interaction, art and the plot itself let the user guess what is lying behind the journey of Wanda and Agro. I would like to thank Nicholas Rotondo, the original writer, for the really interesting article.

One of the last colossi. Announced by a melancholy song.
This particular way of creating the title led thousands of people to interpret the narrative aspects of SOTC, its probable link to Ico, the roles of the lady and Dormin. But also led superficial players to snub the game, because they want to be guided, not to be challenged philosophically. That's why hardcore gamers label SOTC as 'sixteen bosses then a disappointing ending' and I label it as 'the best adventure on PS2'. Fumido Ueda needed something to add hardcore gamers to his crowd of praisers, but failed.

SOTC didn't have poor graphics. The technical side of the Sony game is exceptional, maybe the best on the console. The land in which the characters wander is infinite, the colossi are huge and challenging, the control system is almost perfect. The sensation of facing an excellent product, on the level of the other PS2 blockbusters, was real. So, nobody in the technical team is to be blamed, and neither Ueda himself who signed a masterpiece in terms of game design.
We now know that Shadow of the Colossus has an incredible amount of design and technical aspects that redefine a genre. It's not an actual action game, it's a mixture and usually a mixture leads to success. But SOTC is not a great success, at least compared to his enormous value. All the aspects concur to create an unique experience.

We were speaking about orchestras. SOTC is the song, well played by a lot of different instruments (art, plot, music effects, design concepts). Ueda and his team are the musicians. So, where are the solo musicians?
Maybe, to reunite the best orchestra in the World we could ask to the best viola player in the world to join us, and so we could do whith flute, piano, drum, guitar. Is this model applyable to videogames?
What if we put the producer of GTA to manage a new project by Ueda? The new idea would sell more. We'd be able to reunite all the players under the same flag. The producers would edit the storyline in a suitable way to let it be either fascinating and able to keep button-breakers close to the game. We could do the same thing with the technical department, with the marketing one, etc.

Then, everybody will be able to play that game, to reach its end and feel in the same way I felt finishing SOTC. These are the most important things: a genius in the game design and someone who can direct his team in a market-favorable way.

SPOILER:
The secret garden
Yes, you're right, I should get back to pointers now...

Thursday 7 October 2010

Finding negativity in beautiful spaces - 05th October 2010

Speaking about Online Gaming or Massive Multi-player Online, the first title which comes to my mind is not one of those 1000 FPS Unreal-like obstructing your lines, but a golf simulation called Shot-Online. When in the last days, discussing about problems in Online gaming, we were taught about the possibility for the programmers to 'cheat' the players, because of speed issues in handling a great amount of data coming from several platforms, I had no idea of what we were discussing. In SO you play following turns, wait for the other players to complete their next stroke, and then you have 30 to 60 seconds to hit the ball. Everything linear, like in real golf, everything under control, even if simulation (weather conditions, ball bounce, holes conformation) does mean a great part of SO success and aren't in any measure sacrificed.

Shot Online character creation screen


But I have to admit that managing 8 or 16 playing characters all in one must be something very painful for any system. All running, all shooting, all possibly involved in the action. Yes, I can guess why AI has to intervene and put on the brakes of extreme simulation in those cases. Programmers limit you, that's all they can do to let the game run as fast as you are used to see in the single player mode. Considering that someone doesn't even play the single player mode after buying an FPS, they are more than justified.

So, my personal experience cannot help me out in finding how I got cheated in the past.
No, wait, not so fast.

I love football. I mean American football. It's a great sport, where tactics and technique reach their perfect balance, and spectacular plays are recurrent. I played many football games, like QB Club, Joe Montana Football, NFL 2Kx and others. Obviously, many Madden titles. The last I bought was Madden 09 All-Play for Nintendo WII. Even if the presentation was not the best and some odious WII features were there to annoy me, most of the appeal was also present. In single player mode I can say that I liked that game, without considering that, for the anger of Xbox and PS users, I was able to design the receivers routes free handed thanks to WiiMote pointer!
But let's go to the bad notes, precisely the Online experience.

In Madden 09 AP you could use two different types of QB passages: the bullet and the lob. The first was performed by leaning WiiMote forward all of a sudden, while the second leaning it very gently. When WiiMote is in the standing position, the value of its Pitch parameter (Y axis) is 1.57. WII decides what type of throw you are doing by just calculating the speed you apply to make the Pitch value go from 1.57 to 0 (flat position).
Playing one on one, player A controls the attack and, big surprise, B controls the defence. To try and reach the opposing QB (A), the defensive lineman can do a lot of possible moves to get rid of the offensive line and, whether he can't go beyond it, to swat or intercept the ball. All is done interpreting the movement of WiiMote, along the axis and using its accelerometer.
You already know how it ends...

Number 55 is trying to reach Brett Favre, shaking WiiMote in many different ways


You cannot throw a bullet, you will always be obliged to execute a lob, no matter how fast you lean your controller. I'm not able to tell you right now how this happened, what kind of memory movements are involved and how the connection limitations interfere with this scheme, but I surely felt frustrated when this happened. Probably, the programmers couldn't tell with the same precision of the normal mode how fast you leaned the controller, so they decided to deny the bullet option from the Online features.
The Online experience dropped quickly, making me prefer the good single player Franchise mode.
I really hope, in a 3 or 4 months time, to come back here, open a post named 'Finding negativity in beautiful spaces - 2' and explain you accurately how technically this shame could happen.

In conclusion, guess what's the best Online WII game...

Tuesday 5 October 2010

FIFA 11: How did we come this far?

Title: FIFA 11
Developer: EA Canada
Platform: PS3
Game modes tested: 1Vs1 multiplayer

Good start, posting a FIFA 10 image on a FIFA 11 related post. Well done!



It's been a long time since I haven't played any FIFA game. Playing with friends, it is common to flat around a standard (in our case Pro Evolution Soccer) and avoid anything else. The reason why this happened is that PES was much better than FIFA, let's say, 10 years ago. Better graphics, better controls, better feeling, much better and more suitable tactics.
But something must be changed if everybody is saying that FIFA has taken the lead. I had the opportunity to play the latest release this weekend (thanks Michael) and, even if now I can confirm that FIFA is the new king, I have to say that I'm a bit disappointed of how things are turning around for soccer simulations.
You could have seen, with the obvious time passing differences, those kind of animations 10 years ago, on FIFA 2000. Players always seem a little 'humpbacked' and clumsy when they try to pass the ball backwards. And at least two generations have passed since that day.
Chiellini might not be a great 'Casanova' but he is not that humpbacked!

Another thing: FIFA encourages pressure. If you press you will get the ball back. When everybody learns it, you'll end up pursuing players more than playing the football. With good results, considering that, unlike PES, you can retrieve the ball and press with the same button. This particular game feature halves the fun in multiplayer sessions.
If it is true that games come out 6 months after they have been completed because programmers have to take away many new stuff because they do not work at the moment, why don't wait a couple of years before coming out with a new game? Let FIFA out with the title 'FIFA 11/12'. You can update rosters online, or stadiums, or everything else, but your core programming team can go on and deliver something really different. When KONAMI realised that, we had PES 2 and PES 5, the best simulations of the PS2 era.
Unfortunately, nobody is going to follow my advice, and they're going out and buy any FIFA or PES (or Madden, or NHL, or NBA Live) coming out every single year. That's how the video gaming World goes nowadays, and that's how players wanted it to go. If they had wanted it another way, maybe now I would have played something better.

Anyway, far from footballistic perfection, FIFA 11 stands as one of the most outstanding soccer videogaming experiences. I really love the way you have to chase the ball once it is passed towards you and the genuine feeling with counter-attacks. Put the ball between the defensive and midfielder line, take Kaka` or Pastore or Snejider on that ball and see how they can prove their divine status.
I appreciate how strikers behave in these cases, proposing for the through pass in a smart way. In addition, you can, more than what you do with PES, see the difference between using Ronaldinho or Ben Arfa, for example. Not only on the graphics side.
This is not a review, just another blog entry. I'm not giving any mark, I just can say that I had a good time playing. Just because soccer is not like that from FIFA, it doesn't mean the game cannot be fun.

Friday 1 October 2010

The contradiction - 30th sept 2010

The today additional induction was a really appreciated thing. Meet one more time before the course gets under way. Simply brilliant. And the explanations we had were nothing less.
A good hour spent keeping everybody calm about the difficulty of the teachings and adding information about the topics: PS3 programming, differences with the XNA suite, a brief look at what has been done in the past and to what we are expected to do this year.
I'm totally excited about the opportunity I grabbed and I really look forward to next week lectures, as I look forward to all the awesome thing this course is going to teach me, since the initial fear about my multiple lacks of heavy programming have been taken away for the moment.
But (and don't tell me you weren't expecting a 'but' somewhere in this post) something is not completely clear to me.
During our meeting the lecturer told us that games are nothing but streams of data conveyed in a certain way by a little set of instructions. He didn't mention, or I didn't get it, that games are most of all an artistic work obtained with a deep creative interaction between software house members. I know, we are not supposed to know this and we are (will be, maybe) basically programmers, but I think it is not fair that if someone of us has a different approach to the video-gaming industry he has to throw it away in the rubbish.
That's why this blog was born. To make my philosophical thoughts float above or under or in between this vital data streams, without denying them.
I'm absolutely not complaining and I'm more than ever convinced about my choice. I just want to make sure all this numbers, all this instructions, all this programming don't drain energy from my will to face the amusement dynamics and explore gaming solutions.
I'm happy to be a little “different”. Nobody ever says the word Nintendo when I speak with my peers, and I think that it is almost obvious since the course is intended to be a way to get into the high-programming positions, something not hugely required in Nintendo or other developers who privileges creativity over graphics or technological machine level solutions.
Maybe at the end of this academic year I'll be a decent programmer and an awesome video games reviewer, or perhaps the opposite or neither things. One thing is sure: I'll be playing my games, I'll be heavily interacting with game designers or graphic artists colleagues.
Leaving the room at the end of our today session, the lecturer told us: “Play games!”. To me, it sounds like a contradiction with what he said in the previous 59 minutes. I hope, in a 365 day time, not to contradict myself.