User interaction and gameplay Scripting AI Physics and

  • Slides: 24
Download presentation
User interaction and gameplay: Scripting, AI, Physics, and Behaviors l How are Players and

User interaction and gameplay: Scripting, AI, Physics, and Behaviors l How are Players and NPCs controlled? – Player’s interface – Scripting, AI, Physics, Behaviors l Determines gameplay

User Interface l Manual (hardware) – Keyboard, mouse – Controller: analog mini-sticks, D-pad, analog

User Interface l Manual (hardware) – Keyboard, mouse – Controller: analog mini-sticks, D-pad, analog buttons l Visual (screen display) – Active: menus, actions – Passive: status, HUDS – Score, lives, power, map, etc. – Split-screen, Whole screen, Invisible

User Interface: Unreal l Controllers are non-physical actors which can be attached to a

User Interface: Unreal l Controllers are non-physical actors which can be attached to a pawn to control its actions. – Player. Controllers are used by human players to control pawns – AIControllers are used to implement the artificial intelligence for the pawns they control. l AIScripts can be associated with pawns placed in levels to modify their AIControllers. – Scripted. Controllers can be used to make a pawn follow a scripted sequence l HUD – Uses 2 D Canvas

User Interface: VRML/X 3 D l Sensor Nodes: – Drag Sensors: l Touch. Sensor,

User Interface: VRML/X 3 D l Sensor Nodes: – Drag Sensors: l Touch. Sensor, Sphere. Sensor, Plane. Sensor, etc. – Proximity Sensor – Visibility Sensor l HUD Prototype – Moves 3 D object along with viewpoint

Scripting Native support the major concepts of time, state, properties, and networking (replication) which

Scripting Native support the major concepts of time, state, properties, and networking (replication) which traditional programming languages don't address. l Safety l – a pointerless environment with automatic garbage collection – a safe client-side execution "sandbox l To enable rich, high level programming in terms of game objects and interactions rather than bits and pixels.

Scripting l Slow – C++ : 50 M base language instructions per second –

Scripting l Slow – C++ : 50 M base language instructions per second – Unreal. Script: 2. 5 million - a 20 X performance hit. l create animation-driven or time-driven code – Exploit latent functions (like Finish. Anim and Sleep)

Scripting: Time l Most engines use Ticks – smallest unit of time in which

Scripting: Time l Most engines use Ticks – smallest unit of time in which all actors in a level are updated. A tick typically takes between 1/100 th to 1/10 th of a second. – limited only by CPU power; the faster machine, the lower the tick duration is. Synchronous vs. Asynchronous l Zero-time vs. Latent l Event cascade l

Scripting Examples: Unreal. Script l Actor (extends Object) is the parent class of all

Scripting Examples: Unreal. Script l 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. l 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: Unreal. Script function Modify. Player(Pawn Other) { local x. Pawn x; //x

Scripting Examples: Unreal. Script function Modify. Player(Pawn Other) { local x. Pawn x; //x is a variable x = x. Pawn(Other); if (x != None) { x. Max. Multi. Jump = Multi. Jump. Count; x. Multi. Jump. Boost = Multi. Jump. Boost; x. Health = Starting. Health; x. Health. Max = Maximum. Health x. Super. Health. Max = Super. Duber. Maximum. Health } }

l Scripting Functionality: World Awareness native final function Actor Trace(Hit. Location, Hit. Normal, Trace.

l Scripting Functionality: World Awareness native final function Actor Trace(Hit. Location, Hit. Normal, Trace. End, Trace. Start, b. Trace. Actors, 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. l Use Trigger – If a human controlled pawn is within the proximity of this trigger and hits their USE key, it activates this trigger. l VRML: Proximity, Collision, Gravity, Visibility nodes

Scripting Examples: Unreal Animation Blending Multiple animation channels/stages are used to blend into the

Scripting Examples: Unreal Animation Blending Multiple animation channels/stages are used to blend into the animation track. l native final function Anim. Blend. Params( int Stage, Blend. Alpha, In. Time, Out. Time, Bone. Name) l – Before playing animation on any channel, you need to call Anim. Blend. Params 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 Blend. Alpha 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;

Scripting Examples: VRML Character Control function mouseinput(val, t){ newrot. angle=calcangle(val. x, val. y); touchval=val; mlen=val. length(); if (mlen) body 2. rotation=newrot; loco(mlen, t); }

Scripting Examples: VRML function keyinput(k, t){ if (k==106){ //jump stand. stop. Time=walk. stop. Time=run.

Scripting Examples: VRML function keyinput(k, t){ if (k==106){ //jump stand. stop. Time=walk. stop. Time=run. stop. Time= jump. start. Time=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

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; body 2. rotation=newrot; } if (k==37){ //left- turn newrot. angle= newrot. angle +. 39; body 2. rotation=newrot; } //16 th of turn

Scripting Examples: VRML if (mlen<0) mlen=0; touchval. x= mlen * Math. sin(newrot. angle); touchval.

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. start. Time=t; walk.

Scripting Examples: VRML function loco(mlen, t){ if (mlen<0. 4){ //print('STOP'); stand. start. Time=t; walk. stop. Time=t; run. stop. Time=t; }else if (mlen<2. 9){ //print('WALK'); stand. stop. Time=t; walk. start. Time=t; run. stop. Time=t; walk. cycle. Interval = 4 - (1. 0 * mlen); }else{ // print('RUN'); stand. stop. Time=t; walk. stop. Time=t; run. start. Time=t; run. cycle. Interval = 0. 80 + (2. 0/(mlen-1. 9)); }

Scripting Examples: VRML function engine(val, time){ //advance position each frame if (lasttime){ if (touchval.

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 l Strong AI: the ability to perform activities normally thought to require

Artificial Intelligence l Strong AI: the ability to perform activities normally thought to require intelligence, learning, and adapting. l Weak AI: specialized intelligent qualities. l Deterministic- predictable – Path Planning l Nondeterministic – uncertainty – NPC learning to adapt to fighting tactics

Artificial Intelligence Chasing and Evading & Pattern movement l Flocking l Pathfinding l –

Artificial Intelligence Chasing and Evading & Pattern movement l Flocking l Pathfinding l – A* algorithm Logic: Finite State Machines, Fuzzy Logic l Probability l – Bayesian l Adaptive – Neural Networks – Genetic Algorithms

Artificial Intelligence: Unreal AI Scripting allows enemies (and friends) to be controlled easily via

Artificial Intelligence: Unreal AI Scripting allows enemies (and friends) to be controlled easily via external files that can be easily changed without map rebuilding. l 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 l

Artificial Intelligence: Unreal : Marine. Patrol ontrigger Change. Marine. Patrol gotolabel Marine. Patrol 2

Artificial Intelligence: Unreal : Marine. Patrol ontrigger Change. Marine. Patrol gotolabel Marine. Patrol 2 gotoactor Path. Node 0 gotoactor Path. Node 1 sleep 2 gotolabel Marine. Patrol : Marine. Patrol 2 ontrigger Change. Marine. Patrol gotolabel Marine. Patrol gotoactor Path. Node 2 gotoactor Path. Node 3 sleep 2 gotolabel Marine. Patrol 2

Physics l Collisions, gravity, falling, explosions, etc. – should be used selectively in your

Physics l Collisions, gravity, falling, explosions, etc. – should be used selectively in your level so as not to overwhelm the engine. NOTE: Don’t confuse with: l 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 l walking, running, crouch walking, swimming, flying, jumping, falling, landing, and idling.

Physics-based Animation l walking, running, crouch walking, swimming, flying, jumping, falling, landing, and idling. l functionality for playing arbitrary animations not based on movement.

Physics-based Animation // Play appropriate idle animations simulated function Play. Waiting(){ if (Physics ==

Physics-based Animation // Play appropriate idle animations simulated function Play. Waiting(){ if (Physics == PHYS_Falling) Loop. Anim(Falling. Anim, 1. 0, 0. 2); else if (Physics == PHYS_Flying) Loop. Anim(Fly. Idle, 1. 0, 0. 2); else if (Physics == PHYS_Swimming) Loop. Anim(Swim. Idle, 1. 0, 0. 2); else { if (b. Is. Crouched) Loop. Anim(Crouch. Idle, 1. 0, 0. 2); else Loop. Anim(Stand. Idle, 1. 0, 0. 2); } }