1 / 81

Game System

Game System. Simplify Your Thinking into Modula (1/2). Control system User input Mouse or keyboard Keyboard layout Camera control View angle View range Interaction with player A “walk through” system Combat system Controls Motion management and blending NPC AI FX Visual Audio.

kalia-neal
Download Presentation

Game System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Game System

  2. Simplify Your Thinking into Modula (1/2) • Control system • User input • Mouse or keyboard • Keyboard layout • Camera control • View angle • View range • Interaction with player • A “walk through” system • Combat system • Controls • Motion management and blending • NPC AI • FX • Visual • Audio

  3. Simplify Your Thinking into Modula (2/2) • Reward system • Number system • Levels • Damage • User Interface • Menu • Mini-map • Messages • Blood bar • Caption • The main program • Main loop • Level management • Configuration • Save/Load

  4. Game AI Steering Behavior

  5. Motion Behavior A Hierarchy of Motion Behavior • Action selection • Steering • Locomotion

  6. Action Selection • Game AI engine • State machine • Discussed in “Finite State Machine” section • Goals • Planning • Strategy • Scripting • Assigned by players • Players’ input

  7. Steering • Path determination • Path finding or path planning • Discussed in “Path Finding” • Behaviors • Seek & flee • Pursuit & evasion • Obstacle avoidance • Wander • Path following • Unaligned collision avoidance • Group steering

  8. Locomotion • Character physically-based models • Movement • Turn right, move forward, … • Animation • By artists • Implemented / managed by game engine

  9. A Simple Vehicle Model (1/2) • A point mass • Linear momentum • No rotational momentum • Parameters • Mass • Position • Velocity • Modified by applied forces • Max speed • Top speed of a vehicle • Max steering force • Self-applied • Orientation • Car • Aircraft

  10. A Simple Vehicle Model (2/2) • Local space • Origin • Forward • Up • Side • Steering forces • Asymmetrical • Thrust • Braking • Steering • Velocity alignment • No slide, spin, … • Turn

  11. Euler Integration • The approach : • Steer_force = Truncate(streer_direction, Max_force) • Acceleration = Steer_force / mass • Velocity = Truncate(Velocity + Acceleration, Max_speed) • Position = Position + Velocity

  12. Seek & Flee Behaviors • Pursuit to a static target • Steer a character toward to a target position • “A moth buzzing a light bulb” • Flee • Inverse of seek • Variants • Arrival • Pursuit to a moving target • Seek Steering force • desired_velocity = normalize(target - position)*max_speed • steering = desired_velocity – velocity

  13. Arrival Behavior • One of the idea : a stopping radius • Outside the radius, arrival is identical to seek • Inside the radius, the speed is ramped down to zero • target_offset = target – position • distance = length(target_offset) • ramped_speed = max_speed*(distance/slowing_distance) • clipped_speed = minimum(ramped_speed, max_speed) • desired_velocity = (clipped_speed/distance)*target_offset • steering = desired_velocity – velocity

  14. Pursuit & Evasion Behaviors • Estimate the prediction interval T • T = Dc • D = distance(pursur, quarry) • c = turning parameter • Target is moving • Apply seek or flee to the target’s predicted position • Variants • Offset pursuit • “Fly by”

  15. Obstacle Avoidance Behavior steering force • Use bounding sphere • Not collision detection • Probe • A cylinder lying along forward axis • Diameter = character’s bounding sphere • Length = speed (means Alert range) • Find the most threaten obstacle • Nearest intersected obstacle • Steering

  16. Wander Behavior • Random steering • One solution : • Retain steering direction state • Constrain steering force to the sphere surface located slightly ahead of the character • Make small random displacements to it each frame • A small sphere on sphere surface to indicate and constrain the displacement • Another one : • Perlin noise • Variants • Explore

  17. Path Following Behavior • The path • Spine • A spline or poly-line to define the path • Pipe • The tube or generated cylinder by a defined “radius” • Following • A velocity-based prediction position • Inside the tube • Do nothing about steering • Outside the tube • “Seek” to the on-path projection • Variants • Wall following • Containment

  18. Flow Field Following Behavior • A flow field environment is defined. • Virtual reality • Not common in games

  19. Unaligned Collision Avoidance Behavior • Turn away from possible collision • Predict the potential collision • Use bounding spheres • If possibly collide, • Apply the steering on both characters • Steering direction is possible collision result • Use “future” possible position • The connected line between two sphere centers

  20. Steering Behaviors for Groups of Characters • Steering behaviors determining how the character reacts to the other characters within his/her local neighborhood • The behaviors including : • Separation • Cohesion • Alignment

  21. The Local Neighborhood of a Character The Neighborhood • The local neighborhood is defined as : • A distance • The field-of-view • Angle

  22. Separation Behavior • Make a character to maintain a distance from others nearby. • Compute the repulsive forces within local neighborhood • Calculate the position vector for each nearby • Normalize it • Weight the magnitude with distance • 1/distance • Sum the result forces • Negate it

  23. Cohesion Behavior • Make a character to cohere with the others nearby • Compute the cohesive forces within local neighborhood • Compute the average position of the others nearby • Gravity center • Apply “Seek” to the position

  24. Alignment Behavior • Make a character to align with the others nearby • Compute the steering force • Average the together velocity of all other characters nearby • The result is the desired velocity • Correct the current velocity to the desired one with the steering force

  25. Flocking Behavior • “Boids Model of Flocks” • [Reynolds 87] • Combination of : • Separation steering • Cohesion steering • Alignment steering • For each combination including : • A weight for combing • A distance • An Angle

  26. Leader Following Behavior • Follow a leader • Stay with the leader • “Pursuit” behavior (Arrival style) • Stay out of the leader’s way • Defined as “next position” with an extension • “Evasion” behavior when inside the above area • “Separation” behavior for the followers

  27. Behavior Conclusion • Wall following • Containment • Flow field following • Unaligned collision avoidance • Separation • Cohesion • Alignment • Flocking • Leader following • A simple vehicle model with local neighborhood • Common steering behaviors including : • Seek • Flee • Pursuit • Evasion • Offset pursuit • Arrival • Obstacle avoidance • Wander • Path following • Combining the above behaviors in your application

  28. Game AI Finite State Machine

  29. Introduction (1/2) • Finite State Machine (FSM) is the most commonly used game AI technology today. • Simple • Efficient • Easily extensible • Powerful enough to handle a wide variety of situations • Theory (simplified) • A set states, S • An input vocabulary, I • Transition function, T(s, i) • Map a state and an input to another state

  30. Introduction (2/2) • Practical use • State • Behavior • Transition • Across states • Conditions • It’s all about driving behavior • Flow-chart diagram • UML State chart • Arrow • Transition • Rectangle • State

  31. An Example of FSM As a Diagram Monster in sight Gather Treasure Flee No monster Monster dead Cornered Fight

  32. FSM for Games • Character AI • “Decision-Action” model • Behavior • Mental state • Transition • Players’ action • The other characters’ actions • Some features in the game world

  33. Implement FSM • Code-based FSM • Simple Code One Up • Straightforward • Most common • Macro-assisted FSM Language • Data-Driven FSM • FSM Script Language

  34. Coding an FSM – Code Example 1 void RunLogic(int *state) { switch(*state) { case 0: // Wander Wander(); if (SeeEnemy()) *state = 1; if (Dead()) *state = 2; break; case 1: // Attack Attack(); *state = 0; if (Dead()) *state = 2; break; case 2: // Dead SlowlyRot(); break; } }

  35. Coding an FSM – Code Example 2 void RunLogic(FSM *fsm) { // Do action based on the state and determine next input input = 0; switch(fsm->GetStateID()) { case 0: // Wander Wander(); if (SeeEnemy()) input = SEE_ENEMY; if (Dead()) input = DEAD; break; case 1: // Attack Attack(); input = WANDER; if (Dead()) input = DEAD; break; case 2: // Dead SlowlyRot(); break; } // DO state transition based on computed input fsm->StateTransition(input); }

  36. Mealy & Moore Machines • Mealy machine • A Mealy machine is an FSM whose actions are performed on transitions • Moore machine • A Moore machine’s actions reside in states • More intuitive for game developers

  37. FSM Language Use Macros • Coding a state machine directly causes lack of structure • Going complex when FSM at their largest • Use macros • Beneficial properties • Structure • Readability • Debugging • Simplicity

  38. FSM Language Use Macros – An Example #define BeginStateMachine … #define State(a) … … bool MyStateMachine::States(StateMachineEvent event, int state) { BeginStateMachine State(0) OnUpdate Wander(); if (SeeEnemy()) SetState(1); if (Dead()) SetState(2); State(1) OnUpdate Attack(); SetState(0); if (Dead()) SetState(2); State(2); OnUpdate RotSlowly(); EndStateMachine }

  39. Data-Driven FSM • Scripting language • Text-based script file • Transformed into • C++ • Integrated into source code • Bytecode • Interpreted by the game • Authoring • Compiler • AI editing tool • Game • FSM script engine • FSM interface

  40. Data-Driven FSM Diagram Authoring Games FSMs FSM Script Engine bytecode Compiler Artist, Designers, & Developers AI Editing Tool FSM Interface Condition & Action Code Game Engine Condition & Action Vocabulary

  41. AI Editing Tool for FSM • Pure text • Syntax ? • Visual graph with text • Used by Designers, Artists, or Developers • Non-programmers • Conditions & action vocabulary • SeeEnemy • CloseToEnemy • Attack • …

  42. FSM Interface • Facilitating the binding between vocabulary and game world • Glue layer that implements the condition & action vocabulary in the game world • Native conditions • SeeEnemy(), CloseToEnemy() • Action library • Attack(…)

  43. FSM Script Language Benefits • Accelerated productivity • Contributions from artists & designers • Ease of use • Extensibility

  44. Processing Models for FSMs • Processing the FSMs • Evaluate the transition conditions for current state • Perform any associated actions • When and how ? • Depend on the exact need of games • Three common FSM processing models • Polling • Event-driven • Multithread

  45. Polling Processing Model • Processing each FSM at regular time intervals • Tied to game frame rate • Or some desired FSM update frequency • Limit one state transition in a cycle • Give a FSM a time-bound • Pros • Straightforward • Easy to implement • Easy to debug • Cons • Inefficiency • Some transition are not necessary to check every frame • Careful design to your FSM

  46. Event-driven Processing Model • Designed to prevent from wasted FSM processing • An FSM is only processed when it’s relevant • Implementation • A Publish-subscribe messaging system (Observer pattern) • Allows the engine to send events to individual FSMs • An FSM subscribes only to the events that have the potential to change the current state • When an event is generated, the FSMs subscribed to that events are all processed • “As-needed” approach • Should be much more efficient than polling ? • Tricky balance for fine-grained or coarse-grained events

  47. Multithread Processing Model • Both polling & event-driven are serially processed • Multithread processing model • Each FSM is assigned to its own thread for processing • Game engine is running in another separate thread • All FSM processing is effectively concurrent and continuous • Communication between threads must be thread-safe • Using standard locking & synchronization mechanisms • Pros • FSM as an autonomous agent who can constantly and independently examine and react to his environment • Cons • Overhead when many simultaneous characters active • Multithreaded programming is difficult

  48. Interfacing with Game Engine (1/2) • FSMs encapsulate complex behavior logic • Decision, condition, action, … • Game engine does corresponding • Character animation, movements, sounds, … • The interface : • Code each action as a function • Need recompile if any code is changed • ie., FleeWolf() • Callbacks • Function pointers • ie., actionFunction[fleeWolf]() • Container method • actionFunctions->FleeWolf(); • DLL

  49. Interfacing with Game Engine (2/2) class AArmyUnit : public FnCharacter { … void DoAttack(…); } AArmyUnit *army; army->Object(…); army->MoveForward(dist, …); … army->DoAttack(…); • Take TheFly3D as example:

More Related