Table Of ContentHardcore AI for Computer Games and Animation
SIGGRAPH98 CourseNotes
by
JohnDavidFunge
Copyright c 1998byJohnDavid Funge
(cid:13)
-ii-
Abstract
Hardcore AI for Computer Games and Animation
SIGGRAPH98 CourseNotes
JohnDavidFunge
1998
WelcometothistutorialonAIforComputerGamesandAnimation.Thesecoursenotesconsistoftwoparts:
PartIisashortoverviewthatmissesoutlotsofdetails.
PartIIgoesintoallthesedetailsingreatdepth.
-iii-
-iv-
Biography
JohnFunge is a memberof Intel’sgraphicsresearchgroup. He receiveda BS in MathematicsfromKing’sCollege
Londonin1990,aMSinComputerSciencefromOxfordUniversityin1991,andaPhDinComputerSciencefromthe
UniversityofTorontoin1998.ItwasduringhistimeatOxfordthatJohnbecameinterestedincomputergraphics.He
wascommissionedbyChannel4televisiontoperformapreliminarystudyonaproposedcomputergameshow. This
madehimacutelyawareofthedifficultiesassociatedwithdevelopingintelligentcharacters.Therefore,forhisPhDat
theUniversityofTorontohesuccessfullydevelopedanewapproachtohigh-levelcontrolofcharactersingamesand
animation.Johnistheauthorofseveralpapersandhasgivennumeroustalksonhiswork,includingatechnicalsketch
at SIGGRAPH 97. His currentresearch interests include computer animation, computer games, intervalarithmetic
andknowledgerepresentation.
-v-
-vi-
Hardcore AI for Computer Games and Animation
Siggraph Course Notes (Part I)
JohnFungeand XiaoyuanTu
MicrocomputerResearch Lab
Intel Corporation
john funge|xiaoyuan tu @ccm.sc.intel.com
f g
Abstract
Recent work in behavioral animation has taken impressive steps toward autonomous, self-animating
characters for use in production animation and computer games. It remains difficult, however, to direct
autonomous characters to perform specific tasks. Toaddress this problem, we explore the use of cognitive
models. Cognitive models go beyond behavioral models in that they govern what a character knows, how
thatknowledgeisacquired,andhowitcanbeusedtoplanactions. Tohelpbuildcognitivemodels,wehave
developedacognitivemodelinglanguage(CML).UsingCML ,wecandecomposecognitivemodelinginto
first giving the character domain knowledge, and then specifying the required behavior. The character’s
domain knowledge is specified intuitively in terms of actions, their preconditions and their effects. To
direct thecharacter’s behavior, theanimator need onlyspecify abehavior outline, or“sketch plan”, andthe
character will automatically work out a sequence of actions that meets the specification. A distinguishing
feature of CML is how we can use familiar control structures to focus the power of the reasoning engine
onto tractable sub-tasks. This forms an important middle ground between regular logic programming and
traditional imperative programming. Moreover, this middle ground allows many behaviors to be specified
morenaturally, moresimply, moresuccinctly andatamuchhigher-level thanwouldotherwise bepossible.
Inaddition, by using interval arithmetic to integrate sensing into ourunderlying theoretical framework, we
enable characters to generate plans of action even when they find themselves in highly complex, dynamic
virtual worlds. We demonstrate applications of our work to “intelligent” camera control, and behavior
animationforcharacters situated inaprehistoric worldandinaphysics-based underseaworld.
Keywords: ComputerAnimation, Knowledge, Sensing, Action,Reasoning, Behavioral Animation, Cogni-
tiveModeling
1 Introduction
Modeling for computer animation addresses the challenge of automating a variety of difficult animation
tasks. An early milestone was the combination of geometric models and inverse kinematics to simplify
keyframing. Physical modelsforanimating particles, rigidbodies, deformable solids, andfluidsoffercopi-
ousquantities ofrealisticmotionthroughdynamicsimulation. Biomechanicalmodelingemployssimulated
physics to automate the realistic animation of living things motivated by internal muscle actuators. Re-
searchinbehavioralmodelingismakingprogresstowardsself-animatingcharactersthatreactappropriately
toperceived environmental stimuli.
In this paper, weexplore cognitive modeling for computer animation. Cognitive models go beyond be-
havioralmodelsinthattheygovernwhatacharacterknows,howthatknowledgeisacquired,andhowitcan
be used to plan actions. Cognitive models are applicable to directing thenew breed of highly autonomous,
quasi-intelligent characters that are beginning to find use in animation and game production. Moreover,
cognitivemodelscanplaysubsidiary rolesincontrolling cinematography andlighting.
Wedecomposecognitivemodelingintotworelatedsub-tasks: domainspecification andbehaviorspeci-
fication. Domainspecificationinvolvesgivingacharacterknowledgeaboutitsworldandhowitcanchange.
Behavior specification involves directing the character to behave in a desired way within its world. Like
otheradvancedmodelingtasks,bothofthesestepscanbefraughtwithdifficultyunlessanimatorsaregiven
therighttoolsforthejob. Tothisend,wedevelopacognitivemodelinglanguage, CML.
CML rests on solid theoretical foundations laid by artificial intelligence (AI) researchers. This high-
level language provides an intuitive way to give characters, and also cameras and lights, knowledge about
their domain in terms of actions, their preconditions and their effects. We can also endow characters with
a certain amount of “commonsense” within their domain and we can even leave out tiresome details from
thespecificationoftheirbehavior. Themissingdetailsareautomatically filledinatrun-timebyareasoning
engineintegraltothecharacter whichdecides whatmustbedonetoachievethespecifiedbehavior.
Traditional AIstyleplanning certainly falls under thebroad umbrella ofthis description, but thedistin-
guishing features of CML are the intuitive way domain knowledge can be specified and how it affords an
animator familiar control structures to focus the power of the reasoning engine. This forms an important
middle ground between regular logic programming (as represented by Prolog) and traditional imperative
programming (as typified by C). Moreover, this middle ground turns out to be crucial for cognitive mod-
eling in animation and computer games. In one-off animation production, reducing development time is,
withinreason,moreimportantthanfastexecution. Theanimatormaytherefore choosetorelymoreheavily
on the reasoning engine. When run-time efficiency is also important our approach lends itself to an incre-
mental style of development. We can quickly create a working prototype. If this prototype is too slow, it
mayberefinedbyincludingmoreandmoredetailedknowledgetonarrowthefocusofthereasoningengine.
2 Related Work
Badler[3]andtheThalmanns[13]haveappliedAItechniques[1]toproduceinspiringresultswithanimated
humans. Tu and Terzopoulos [18] have taken impressive strides towards creating realistic, self-animating
graphicalcharactersthroughbiomechanicalmodelingandtheprinciplesofbehavioralanimationintroduced
in the seminal work of Reynolds [16]. A criticism sometimes levelled at behavioral animation methods
is that, robustness and efficiency notwithstanding, the behavior controllers are hard-wired into the code.
BlumbergandGalyean[6]begintoaddresssuchconcernsbyintroducingmechanismsthatgivetheanimator
greater control over behavior and Blumberg’s superb thesis considers interesting issues such as behavior
learning[5]. Whilewesharesimilarmotivations,ourworktakesadifferentroute. Oneofthefeaturesofour
approach is that we investigate important higher-level cognitive abilities such as knowledge representation
andplanning.
Thetheoretical basis ofour workisnewtothegraphics community andweconsider somenovelappli-
cations. We employ a formalism known as the situation calculus. The version we use is a recent product
ofthecognitive robotics community[12]. Anoteworthy pointofdeparture fromexisting workincognitive
roboticsisthatwerenderthesituationcalculusamenabletoanimationwithinhighlydynamicvirtualworlds
byintroducing intervalvaluedfluents[9]todealwithsensing.
High-levelcameracontrolisparticularlywellsuitedtoanapproachlikeoursbecausetherealreadyexists
a large body of widely accepted rules that we can draw upon [2]. This fact has also been exploited by two
recent papers [10, 8] on the subject. This previous work uses a simple scripting language to implement
hierarchical finitestatemachinesforcameracontrol.
3 Theoretical Background
The situation calculus is a well known formalism for describing changing worlds using sorted first-order
logic. Mathematical logic is somewhat of a departure from the mathematical tools that have been used in
previous work in computer graphics. In this section, we shall therefore go over some of the more salient
points. Since the mathematical background is well-documented elsewhere (for example, [9, 12]), we only
provide a cursory overview. We emphasize that from the user’s point of view the underlying theory is
completely hidden. Inparticular, auserisnotrequired totypeinaxiomswritteninfirst-order mathematical
logic. Instead, wehavedeveloped anintuitive interaction language thatresembles naturallanguage, buthas
aclearandprecise mapping totheunderlying formalism. Insection 4,wegiveacomplete exampleofhow
touseCML tobuildacognitivemodelfromtheuser’spointofview.
3.1 Domainmodeling
A situation is a “snapshot” of the state of the world. A domain-independent constant S denotes the initial
situation. Anyproperty of the world that can change over time isknown as afluent. A0fluent isafunction,
or relation, with a situation term as (by convention) its last argument. For example Broken is a fluent
thatkeepstrackofwhetheranobject isbrokeninasituation . (x;s)
Primitive actions are the fundamexntal instrument of changesin our ontology. The term “primitive” can
sometimes be counter-intuitive and only serves to distinguish certain atomic actions from the “complex”,
compound actions that we will define in section 3.2. The situation resulting from doing action in
0
situation isgivenbythedistinguished functiondo,suchthat, dos . Thepossibility ofperformaing
0
action isn situation is denoted by a distinguished predicate Psos=s (a;.s)Sentences that specify what the
state ofatheworldmusstbebefore performing someaction areknown(aa;ssp)recondition axioms. Forexample,
itispossible todrop anobject inasituation ifand only ifacharacter isholding it,Poss drop
Holding . InCML ,thisaxixomcanbeexpresssedmoreintuitivelywithouttheneedforlogic(alco(nxn)e;cst)iv,es
andthe(xex;psl)icitsituation argument. 1
actiondrop( )possiblewhenHolding( )
x x
TheconventioninCML isthatfluentstotheleftofthewhenkeywordrefertothecurrentsituation. The
effectsofanactionaregivenbyeffectaxioms. Theygivenecessaryconditionsforafluenttotakeonagiven
value after performing an action. Forexample, theeffect ofdropping anobject isthat the character isno
longer holding theobject intheresulting situation andvice versaforpicking upxanobject. Thisisstated in
CML asfollows.
occurrencedrop( )resultsin!Holding( )
occurrencepickupx( )resultsinHoldingx( )
x x
What comesas asurprise, isthat, anaive translation ofthe above statements into thesituation calculus
does not give the expected results. In particular, there is a problem stating what does not change when an
actionisperformed. Thatis,acharacterhastoworrywhetherdropping acup,forinstance, resultsinavase
turningintoabirdandflyingabouttheroom. Formindlessanimatedcharacters, thiscanallbetakencareof
implicitly bytheprogrammer’s commonsense. Weneedtogiveourthinking characters thissamecommon
sense. They have to be told that, unless they know better, they should assume things stay the same. In AI
this is called the ”frame problem” [14]. If characters in virtual worlds start thinking for themselves, then
1To promote readability all CML keywords willappear inbold type, actions (complex and primitive) will be italicized, and
fluentswillbeunderlined. Wewillalsousevariousotherpredicatesandfunctionsthatarenotfluents.Thesewillnotbeunderlined
andwillhavenamestoindicatetheirintendedmeaning.
theytoowillhavetotackletheframeproblem. Untilrecently,itisoneofthemainreasonswhywehavenot
seenapproaches likeoursusedincomputeranimation orrobotics.
Fortunately, theframeproblemcanbesolvedprovidedcharactersrepresenttheirknowledgeinacertain
way [15]. The idea is to assume that our effect axioms enumerate all the possible ways that the world
can change. This closed world assumption provides the justification for replacing the effect axioms with
successor state axioms. For example, the CML statements given above can now be effectively translated
intothefollowingsuccessorstateaxiomthatCML usesinternallytorepresenthowthecharacter’sworldcan
change. Itstatesthat,provided theactionispossible, thenacharacter isholdinganobject ifandonlyifit
justpicked ituporitwasholding itbefore anditdidnotjustdropit,Poss Holdinxg do
pickup drop Holding . (a;s) ) [ (x; (a;s)) ,
a = (x)_(a 6= (x)^ (x;s))
3.1.1 Sensing
Oneofthelimitations ofthe situation calculus, aswehavepresented itsofar, isthat wemustalways write
downthingsthataretrueabouttheworld. Thisworksoutfineforsimpleworldsasitiseasytoplaceallthe
rules by which the world changes into the successor state axioms. Even in more complex worlds, fluents
that represent the character weare controlling’s internal state are, by definition, always true. Nowimagine
wehaveasimulated worldthatincludes anelaborate thermodynamics modelinvolving advection-diffusion
equations. We would like to have a fluent temp that gives the temperature in the current situation for the
character’s immediate surroundings. What are we to do? Perhaps the initial situation could specify the
correct temperature at the start? However, what about the temperature after a setFireToHouseaction, or a
spillLiquidHeliumaction, or even just twenty clock tick actions? Wecould write asuccessor state axiom that
contains all the equations by which the simulated world’s temperature changes. The character can then
perform multiple forward simulations to know the precise effect of all its possible actions. This, however,
is expensive, and even more so when we add other characters to the scene. With multiple characters, each
character must perform aforward simulation for each ofitspossible actions, andthen for each oftheother
character’spossibleactionsandreactions,andthenforeachofitsownsubsequentactionsandreactions,etc.
Ignoring theseconcerns, imaginethatwecouldhaveacharacter thatcanprecisely knowtheultimateeffect
ofallitsactions arbitrarily faroffintothefuture. Suchacharacter canseemuchfurther intoitsfuturethan
ahumanobserver soitwillnotappear as“intelligent”, butratheras“super-intelligent”. Wecanthinkofan
example of a falling tower of bricks where the character precomputes all the brick trajectories and realizes
it is in no danger. To the human observer, who has no clue what path the bricks will follow, a character
who happily stands around while bricks rain around it looks peculiar. Rather, the character should run for
cover,ortosomesafedistance, basedonitsqualitative knowledge thatnearbyfalling bricksaredangerous.
Insummary, wewouldlikeourcharacters torepresent theiruncertainty aboutsomeproperties oftheworld
untiltheysensethem.
Half of the solution to the problem is to introduce exogenous actions (or events) that are generated by
theenvironmentandnotthecharacter. Forexample,wecanintroduceanactionsetTempthatisgeneratedby
theunderlyingsimulatorandsimplysetsthetemperaturetoitscurrentvalue. Itisstraightforward tomodify
the definition of complex actions, that we give in the next section, to include a check for any exogenous
actionsand,ifnecessary, include theminthesequence ofactionsthatoccur(see[9]formoredetails).
The other half of the problem is representing what the character knows about the temperature. Just
because thetemperature inthe environment haschanged does notmeanthe character should know about it
until it performs a sensing action. In [17] sensing actions are referred to as knowledge producing actions.
Thisisbecausetheydonotaffecttheworldbutonlyacharacter’sknowledgeofitsworld. Theauthorswere
able to represent a character’s knowledge of its current situation by defining an epistemic fluent K to keep
track ofalltheworlds acharacter thinks itmight possibly bein. Unfortunately, theapproach does notlend
itself toeasy implementation. Theproblems revolve around how tospecify the initial situation. Ingeneral,
if we have relational fluents, whose value may be learned through sensing, then there will be initial
n
n 2