290 likes | 297 Views
Dive into the basic techniques of game AI, from finite-state machines to coordination transformations. Hands-on labs, assignments, and a final project will enhance your understanding. Join us on this exciting journey!
E N D
Introduction GAM 376 Robin Burke Winter 2006
Outline • Introductions • Syllabus • Math / Physics • Break • Lab
Me • Helped create the new GAM degree • A long-time fan of computer games • from Space Invaders to Katamari Damacy • An AI researcher by training • But • not a game developer by training or experience
What is Game AI? • Analogy • game AI is to "real" AI as • stage design is to architecture • The goal of game AI is to give the impression of intelligence • to avoid the impression of stupidity • to provide a reasonable challenge for the player
What we will cover • Finite-state machines • the most basic technique for implementing game AI • fundamental to everything else • Steering behaviors • basic behaviors for avoiding stupidity while navigating the world • Path planning • the surprisingly tricky problem of getting from point A to point B • Action planning • assembling sequences of actions • Fuzzy logic • reasoning by degrees
How we will do it • Classes will be 50% lab • first half in the classroom • second half in Rm 707 • 7th floor Game Development Lab • we will visit there tonight • Tools • Buckland's source code • VS 2003
What we will do • 3 homework assignments • one trivial • two non-trivial • 2 group assignments • soccer team • death match bot • final project • mod for Half-Life 2
Final Project • Add a co-operative character to a HL2 level • The character should • follow along through the level • contribute in some way to completing the level • not hinder the player • The character should not be human • helps keep expectations low
Disclaimer • This class is an experiment • We will probably need to adjust as we go along
Begin math / physics 101 • Vectors • Coordinate spaces • Kinematics
Vector • A multi-dimensional quantity • represented by a tuple of numbers • We will deal mostly with 2-D vectors • <2, 5> • 3-D vectors are more mathematically complex • but not fundamentally different • for AI purposes
Vectors • can represent positions • <1,1> is a position 1 unit north and 1 unit east of the origin • can also represent velocities • <3,-4> is a speed of 5 units in a northwesterly direction • other quantities • orientation, acceleration, angle, etc.
Vector operations • Magnitude • v = <x1, y1> • | v | = magnitude(v) = sqrt(x12+y12) • the length of the vector • Adding • <x1, y1> + <x2, y2> = <x1+x2, y1+y2> • Scalar multiplication • <x1, y1> * z = <x1*z, y1*z> • changes only the length • Normalization • v / |v| • makes a vector of length 1 • does not change the orientation of the vector
More vector operations • dot product • <x1, y1> ● <x2, y2> = • x1 * x2 + y1 *y2 • scalar quantity • related to the angle between vectors • cos (angle) = u ● v / | u | | v | • Note • if u and v are normalized (length = 1) • then u ● v is the cosine of the angle between them
Example • we have two agents: a, b • each has a vector position • and a normalized vector orientation • the direction they are facing • turn to face an enemy • agent: Pa, Oa • enemy: Pb, Ob • vector from agent to enemy • Pba = Pb-Pa • normalize it • compute dot product • Pba ● Og • compute inverse cosine • this is the direction to turn
Coordinate transformations • We will always want to move back and forth between coordinate systems • objects each have their own local coordinate systems • related to each other in "world space" • Example • NPC • a character is at a particular position, facing a particular direction • he defines a coordinate system • Door • the door has its own coordinate system • in that system, the handle is in a particular spot • To make the character reach for the handle • we have to make the two coordinate systems interact
Transformations • We know • where the handle is in door space • where the agent's hand is in agent space • what is the vector in agent space • Set of transformations • transform handle location L0 to world space Lw • transform handle location to agent space La • Each transformation • is a translation (changing the origin) • and a rotation changing the orientation
Affine transformations • Usually coordinate transformations are done through matrix multiplications • we multiply a vector by a matrix and get another vector out • The curious thing is • that to do this we have to use vectors and matrices one size larger than our current number of dimensions • you will see <x, y, 1> as the representation of 2-D vector and <x,y,z,1> for 3-D
Efficiency • Mathematical operations are expensive • especially trigonometric ones (inverse cosine) • also square root • multiplication and division, too • Normalization is particularly expensive • square root, squaring and division • We want to consider ways to make our calculations faster • especially if we are doing them a lot
Kinematics • the physics of motion • we worry about this a lot in computer games • moving through space, collisions, etc. • our NPCs have to understand this too in order to not look stupid
Basic kinematics • position • a vector in space • (point position) • for a large object we use a convenient point • classically the center of mass • velocity • the change of position over time • expressed as a vector • pt+1 = pt + vΔt • if we define the time interval Δt to be 1 • we avoid a multiplication
Basic kinematics II • Acceleration • change in velocity over time • also expressed as a vector • vt+1 = vt + a Δt • Pair of difference equations
Numerical methods • But now we have a problem • there is a lag of 1 time step before acceleration impacts position • not physically accurate • We can improve our simulation • finer time step (very expensive) • improved estimation methods • for example instead of using vt, we can use the average of vt and vt+1
Force • Netwon's law • F = m*a • In other words • acceleration is a function of force and mass • Force is also a vector quantity
Example • When a bat hits a ball • we will want to determine the force imparted to the ball • we could simulate this with the mass of the bat and its speed • more likely, we would just have a built-in value • direction of the force • we need to know the angle of the bat when it strikes the ball
What does this have to do with AI? • Imagine a NPC baseball player • he has to decide when to swing • that judgement has to be based on an estimate of the ball's trajectory • When NPC take physical actions • we have to know what the parameters of those actions should be • very often physics calculations are required • not as detailed as the calculations needed to run the game
More complex motions • To handle rotation • we also have to worry about torque and angular momentum • But for the purposes of this class • we will deal only with "particle systems"
End math / physics 101 • For more, take GAM 350