Friday, January 11, 2013

Back to School and hit the ground running!

Ahh it feels great to not only be back at school but to be back to work!  Classes this semester look like a challenge that I can't wait to challenge.  This is my first blog post of the semester and my Intentions from this point forward I hope to do a quick overview of each class and show off what I have accomplished.  But for now since things are just starting I'll give a little overview of each class and what I have on my plate for the first week of classes!

Production II:

This will be the most creative, fun, hard, and time consuming class by far.  I've been teamed up with with 2 designers, an artist and a half with the only goal of the semester is to create a game.  We will be working in an agile production cycle most likely scrum to keep us organized and on task.  Each week  we will present to the class our current iteration and be critiqued on it so there is a lot on the line.   Our team has settled on using Unity for our project (being one of my first real attempt at making a 3D game)  and we have more ideas buzzing around in our heads then we can handle.  No spoilers yet but I'm really excited about our first project, there are a lot of seemingly hard challenges that I already have tons of Ideas on how to crack.  The most exciting part is I'll be using the techniques from AI last semester to simulate crowd behaviors, flee behaviors and chase behaviors.  It's one of the best feelings in the world to see things I learned being put to use! Expect to see a rough prototype next week!

Graphics II:

Math, math, math, and more math.  This class is going to be a struggle but one of the most beneficial ones I'm taking.  For the first half of the year I'll be working in OpenGL to create 3D graphics in C++.  My first attempt at such a thing.  The second half we will change gears and start working on DirectX  that way we will be able to experience both major ways of coding 3D graphics.  Our first assignment is to create compact disk and one other complex shape. Shouldn't be too bad just a few math equations and the computer will do the rest for me. A snapshot will be present next week. Come on Geometry don't fail me now!  

System Software Analysis and Design:  

Architecture!  Our first assignment gives the impression of a blow over class, especially since we are working in C#  however I have a hunch that this class will escalate quickly.  Our first project is to make a contact book really simple, however this class is all about following standards, good architecture,  efficient methods, and design patterns.  So this fairly simple program becomes a little more time consuming as I make sure to cross my T's and dot my I's.  Each week we will present our assignment and then the following week we will re factor them to make it better. A lot of work but by the end of the semester I'm sure my code will be looking better then ever!

Our of class Projects:

Besides class the other good news I bring is after Emailing the correct Legal Teams I've been given the green light to start on my Application!  I'm not going to share what it is just yet but I'll keep posted on any updates.  For now I'll be prototyping in Titanium, a java script based shell which promotes multi-platform production so i can hit both Android and Apple.  However if all goes well I'll end up switching from Titanium once I figure everything out!

That's all for now I gotta get to work!

See you next week!

-Ian

Monday, December 10, 2012

Game AI - Predicting Physics

     Sports, Shooters, Platformers, Adventure, Racing, Arcade, and even games like pong all has some sort of physics in them no matter how simple they may be. These Physics effect objects in the game that directly impact how AI should act in different situations.  Learning to use Physics can help make it so your AI goes from a clueless loser to a competitive challenge.  But I'm not talking about just using Physics to make a game look and feel more realistic, what I'm here to talk about is using our knowledge of in game Physics to allow our AI's to predict the correct outcome based on the world around it, this way our AI looks like it is actually making intelligent decisions.  

     Us humans make judgement based on physics all the time, for example when you are playing catch, when you  go to throw the ball you don't sit there and take the time to accurately calculate how hard to throw the ball and at what angle you should throw it, you have a general feel and understanding that you have picked up just from living in this world of physics everyday.  While the AI in our games don't the those "gut feelings" about how hard to throw a ball, they have the possibility of something I would consider much better, Cold, Hard, Math.  The AI is built on a computer and there is nothing a computer is better at then solving equations, with the correct equations at its side and precise data from the world around it, our AI's have the possibility to never miss a catch, have the perfect shot, and always dodge the projectile. Very quickly you can see just how powerful this type of information can be for an AI. (2)

     This is where the fun starts, the math behind the physics, and accuracy vs efficiency when and what trades off you should make based on the game. Predicting Physics isn't an all or nothing system,  you can tailor how much accuracy you want/need in your game, because in all honestly perfect accuracy isn't always a good as it sounds.  Imaging playing a FPS game where whenever you came into range of an enemy who had you in line of sight you got head shot.  It would make the player very angry very quickly, so while we have the math to make this possible its definitely not the best route to take.  Projectile Math the most common for Games considering to take care of any projectile whether it be a bullet, snowball, football, or something of the likes. Projectile math takes the following variables Gravity(9.81 m/s ^2 on Earth, is usually doubled in games), Angle of Launch, Initial Velocity  initial height, time, and distance traveled. with them you can find any other one if it is unknown.  Considering we control the world in which this AI is running  we should have easy access to gravity, angle, velocity,height and time.  We would normally use this to find out where our projectile is going to land. (2)

For a 2D space (http://www.iforce2d.net/b2dtut/projected-trajectory) has a great tutorial explaining the math behind the magic.  When looking to find where our object will land we use the following equation  

 p(n) = po + nv + (n^2 + n)a/2


p(n) is the position on the nth time step
n is time step
p0 is the starting position at the 0th time step
v is the starting velocity per time step
a is the acceleration due to gravity per time step


Something to keep in mind when calculating where the projectile will land is not always what you want to use.  Using the last time point in the equation is where the bullets,ball,objects are landing.  It would be very terrible in a sport game like football if the AI always went to the point where the ball would hit its feet, it would look very strange catching the ball or miss it all together.  You want to make sure in situations like this as well as shooters that the projectiles end somewhere around chest height.  Obviously this is all based on the projectile being used and isn't a constant rule.(1)

The Equation above is a basic form of the projectile trajectory equation  and is the one most used by games it is recommended for Platforms that don't have the best computing power if you still want realish looking projectiles in that game.  The more worried about reality you are the more processing intensive it becomes.  The example above leaves out a few variables that are definitely present in the real world.  I speak of Drag and Rotation.  These projectiles like projectiles in most games pretend there is no resistances around them, I speak of Air resistance.  While  this is only a slight influences especially on things like bullet projectiles if you want reality  like for a sports game you are going to have to include it and at this point the math becomes much more complicated and processing intensive.  This also goes for rotation, most if not all projectile do rotate at least slightly which will add to lift causing the projects to go higher or farther, once again on low end platforms i would recommend leaving this out as well because the more variables you add the harder the math, the harder the math the more CPU intense it is for you AI to figure out every so many frames and react to it possibly causing the game to slow.(3)

A good example with Air Resistance
 http://phet.colorado.edu/sims/projectile-motion/projectile-motion_en.html

When worrying about air resistance you take the equation that we have above and where we apply the effects of gravity we take the air resistance force and add it with the acting gravity force.  This way the total acting force is now also including Air Resistance.  An example of which is shown here (http://www.riotstories.co.uk/science/projectile-motion-ii-air-resistance-linear-in-speed/)(3)

Just as these equations can become more complicated they can also be simplified for lower end platforms or if the game just doesn't care about looking real.  Below is an example of accurate prediction of shots if there is no negative force acting upon it.  No gravity or resistances,  see how the AI leads in front of the player when there is no obstruction.  This is because the AI is calculating with a similar version of the above formula if the shot will hit the target and when.  In this example the programmer added a slight error margin which allows the AI to not always hit its target, this makes it more playable for the player not always being hit but still making it feel like a challenge.  (2)


This is the core essence and purpose of predicting physics, it allows accurate "smart" seeming AI because they look like they actually know how to aim/throw/block.  They move in a timely matter and if the error margin is small enough it will cause quite a challenge.  (2)









Works Cited
  1. "Box2D Tutorials - Projected Trajectories." Box2D Tutorials - Projected Trajectories -                                                        Iforce2d. Box 2D, 6 Nov. 2011. Web. 11 Dec. 2012.
  2. Millington, Ian, and John David Funge. Artificial Intelligence for Games. Burlington, M          MA: Morgan Kaufmann/Elsevier, 2009. Print.
  3. Sinclair, Steve. "Riotstories." Riotstories. ITest Solutions Ltd, 13 Mar. 2012. Web. 11 Dec. 2012.

Hello World!

Nothing is more fitting for a first blog post of a programmer then the two first words we see printed out in every new language.