Download Scripts and Behaviors

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Philosophy of artificial intelligence wikipedia , lookup

History of artificial intelligence wikipedia , lookup

Ecological interface design wikipedia , lookup

Ethics of artificial intelligence wikipedia , lookup

Artificial intelligence in video games wikipedia , lookup

Intelligence explosion wikipedia , lookup

Existential risk from artificial general intelligence wikipedia , lookup

Transcript
User interaction and gameplay:
Scripting, AI, Physics, and Behaviors

How are Players and NPCs controlled?
– Player’s interface
– Scripting, AI, Physics, Behaviors

Determines gameplay
User Interface

Manual (hardware)
– Keyboard, mouse
– Controller: analog mini-sticks, D-pad, analog buttons

Visual (screen display)
– Active: menus, actions
– Passive: status, HUDS
– Score, lives, power, map, etc.
– Split-screen, Whole screen, Invisible
User Interface:
Unreal

Controllers are non-physical actors which can be
attached to a pawn to control its actions.
– PlayerControllers are used by human players to control
pawns
– AIControllers are used to implement the artificial
intelligence for the pawns they control.

AIScripts can be associated with pawns placed in levels to
modify their AIControllers.
– ScriptedControllers can be used to make a pawn follow
a scripted sequence

HUD
– Uses 2D Canvas
User Interface:
VRML/X3D

Sensor Nodes:
– Drag Sensors:
 TouchSensor, SphereSensor, PlaneSensor, etc.
– Proximity Sensor
– Visibility Sensor

HUD Prototype
– Moves 3D object along with viewpoint
Scripting

Native support the major concepts of time, state,
properties, and networking (replication) which
traditional programming languages don't address.
 Safety
– a pointerless environment with automatic garbage
collection
– a safe client-side execution "sandbox

To enable rich, high level programming in terms
of game objects and interactions rather than bits
and pixels.
Scripting

Slow
– C++ : 50M base language instructions per
second
– UnrealScript: 2.5 million - a 20X performance
hit.

create animation-driven or time-driven code
– Exploit latent functions (like FinishAnim and
Sleep)
Scripting: Time

Most engines use Ticks
– smallest unit of time in which all actors in a level are
updated. A tick typically takes between 1/100th to
1/10th of a second.
– limited only by CPU power; the faster machine, the
lower the tick duration is.

Synchronous vs. Asynchronous
 Zero-time vs. Latent
 Event cascade
Scripting Examples:
UnrealScript

Actor (extends Object) is the parent class of all
standalone game objects in Unreal.
– The Actor class contains all of the functionality needed
for an actor to move around, interact with other actors,
affect the environment, and do other useful gamerelated things.

Pawn (extends Actor) is the parent class of all
creatures and players in Unreal which are capable
of high-level AI and player controls.
Scripting Examples:
UnrealScript
function ModifyPlayer(Pawn Other)
{
local xPawn x; //x is a variable
x = xPawn(Other);
if (x != None) {
x.MaxMultiJump = MultiJumpCount;
x.MultiJumpBoost = MultiJumpBoost;
x.Health = StartingHealth;
x.HealthMax = MaximumHealth x.SuperHealthMax =
SuperDuberMaximumHealth
}
}
Scripting Functionality:
World Awareness

native final function Actor Trace(HitLocation,
HitNormal, TraceEnd, TraceStart, bTraceActors,
Extent, Material)
– casts a ray (aka "traces") into the world and returns
what it collides with first. Trace takes into account both
this actor's collision properties and the collision
properties of the objects Trace may hit.

Use Trigger
– If a human controlled pawn is within the proximity of
this trigger and hits their USE key, it activates this
trigger.

VRML: Proximity, Collision, Gravity, Visibility
nodes
Scripting Examples:
Unreal Animation Blending

Multiple animation channels/stages are used to blend
into the animation track.
 native final function AnimBlendParams( int Stage,
BlendAlpha, InTime, OutTime, BoneName)
– Before playing animation on any channel, you need to call
AnimBlendParams to set up that channel. Channels are
blended in order starting at the base channel (channel 0)
with higher channels blended on top.
– animations played on higher channels will mask animations
played on lower channels, depending on the BlendAlpha of
the higher animation channel and which bones the higher
channel affects.
Scripting Examples:
VRML Character Control
function mouseinput(val,t){
newrot.angle=calcangle(val.x,val.y);
touchval=val;
mlen=val.length();
if (mlen)
body2.rotation=newrot;
loco(mlen,t);
}
Scripting Examples:
VRML
function keyinput(k,t){
if (k==106){ //jump
stand.stopTime=walk.stopTime=run.stopTime=
jump.startTime=t;
mlen=0;
}
if (k==119){ //w - walk
mlen=1.5;
}
if (k==114){ //r- run
mlen=2.9;
}
if (k==104){ //h- halt
mlen=0;
}
Scripting Examples:
VRML
if (k==38){ //up - faster
mlen+= .2;
}
if (k==40){ //down - slower
mlen-= .2;
}
if (k==39){ //right - turn
newrot.angle= newrot.angle - .39;
body2.rotation=newrot;
}
if (k==37){ //left- turn
newrot.angle= newrot.angle + .39;
body2.rotation=newrot;
}
//16th of turn
Scripting Examples:
VRML
if (mlen<0)
mlen=0;
touchval.x= mlen * Math.sin(newrot.angle);
touchval.y= mlen * Math.cos(-newrot.angle);
//print('ang='+newrot.angle);
//print('x='+touchval.x+',y='+touchval.y);
//print('mlen='+mlen);
loco(mlen,t);
}
Scripting Examples:
VRML
function loco(mlen,t){
if (mlen<0.4){
//print('STOP');
stand.startTime=t;
walk.stopTime=t;
run.stopTime=t;
}else if (mlen<2.9){
//print('WALK');
stand.stopTime=t;
walk.startTime=t;
run.stopTime=t;
walk.cycleInterval = 4 - (1.0 * mlen);
}else{
//
print('RUN');
stand.stopTime=t;
walk.stopTime=t;
run.startTime=t;
run.cycleInterval = 0.80 + (2.0/(mlen-1.9));
}
Scripting Examples:
VRML
function engine(val,time){ //advance position each frame
if (lasttime){
if (touchval.length()>=0.4) //not stopped
body.translation=
body.translation.add(touchval.multiply((timelasttime)*.5));
}
lastval=t;
}
Artificial Intelligence

Strong AI: the ability to perform activities
normally thought to require intelligence,
learning, and adapting.
 Weak AI: specialized intelligent qualities.
 Deterministic- predictable
– Path Planning

Nondeterministic – uncertainty
– NPC learning to adapt to fighting tactics
Artificial Intelligence

Chasing and Evading & Pattern movement
 Flocking
 Pathfinding
– A* algorithm

Logic: Finite State Machines, Fuzzy Logic
 Probability
– Bayesian

Adaptive
– Neural Networks
– Genetic Algorithms
Artificial Intelligence:
Unreal

AI Scripting allows enemies (and friends) to be
controlled easily via external files that can be
easily changed without map rebuilding.
 Almost every important NPC (non player
character) in Unreal II has a long and detailed
script behind it controlling its behavious and
actions under various conditions
Artificial Intelligence:
Unreal
:MarinePatrol
ontrigger ChangeMarinePatrol gotolabel
MarinePatrol2
gotoactor PathNode0
gotoactor PathNode1
sleep 2
gotolabel MarinePatrol
:MarinePatrol2
ontrigger ChangeMarinePatrol gotolabel
MarinePatrol
gotoactor PathNode2
gotoactor PathNode3
sleep 2
gotolabel MarinePatrol2
Physics

Collisions, gravity, falling, explosions, etc.
– should be used selectively in your level so as not to
overwhelm the engine.
NOTE: Don’t confuse with:
 PYSICS-BASED ANIMATION
– the motion of the pawn determines what animation the
pawn is playing.
– good for multiplayer situations because each client just
looks at the motion of a given pawn to see what
animation should be playing; no extra information
needs to be transmitted.
Physics-based Animation

walking, running, crouch walking,
swimming, flying, jumping, falling, landing,
and idling.
 functionality for playing arbitrary
animations not based on movement.
Physics-based Animation
// Play appropriate idle animations
simulated function PlayWaiting(){
if (Physics == PHYS_Falling)
LoopAnim(FallingAnim, 1.0, 0.2);
else if (Physics == PHYS_Flying)
LoopAnim(FlyIdle, 1.0, 0.2);
else if (Physics == PHYS_Swimming)
LoopAnim(SwimIdle, 1.0, 0.2);
else {
if (bIsCrouched)
LoopAnim(CrouchIdle, 1.0, 0.2);
else
LoopAnim(StandIdle, 1.0, 0.2);
}
}