Download presentation
Presentation is loading. Please wait.
Published byLydia Miller Modified over 8 years ago
1
Movement Logical and Artificial Intelligence in Games Lecture 3
2
2 Environment Structure Parts of game environment that can physically affect movement (e.g. doors) Player cannot simply push these aside Detail Cosmetic parts of the environment that players cannot collide with in a significant way (e.g. books)
3
3 Living Creatures Affect movement during game Often have been forced into either structure or scenery as needed by game designer Other players and NPC ’ s can be considered obstacles in large crowds It may be best to consider moving creatures as category of their own when considering movement issues
4
4 Defining Space - 1 Human players Have to understand the environment based on imperfect visual information AI characters May get a simplified or incomplete version of the world off line before the game starts (e.g. a list of way points) They may be expected to perceive and interpret the world on-line like humans
5
5 Defining Space - 2 Space is an abstract concept that cannot be fully understood Each representation scheme will involve considerations of design tradeoffs Once an entity has “ figured out ” space it is possible for the entity to determine which parts can be traversed and which cannot
6
6 Dimensions Some game take place in 2D worlds (Warcraft II) and some in 3D (Half Life) It is important to note the the game world dimensions do not always match its rendering Most academic AI deals with 2D movement algorithms In many cases it is permissible to generalize a 2D movement algorithm to 3D
7
7 Pitfalls 2D to 3D Complex environments may contain widgets (e.g. jump pads) that are rare in a 2d world Naively applying the 2D algorithm without custom tailoring it to the problem at hand Gravity plays a role in realistic environments and should not be ignored
8
8 Space Discrete Game environment limited cells (tiles) on a grid using integer coordinates Continuous Have unlimited (real) coordinate values Usually can be done using single precision (32 bit) floating-point numbers
9
9 Time Discrete “ Clock ” advances at regular fixed length intervals Continuous Actions can be continuous and appear concurrent A single CPU shares its clock cycles with each object and a portion of the game code is devoted to determining what happened since the last update (say every 0.1 seconds)
10
10 Conversions For digital computers everything ends up being implemented as if it was discrete It is possible for the game world to use one discrete conversion scheme and the AI different scheme This allows the use of an grid-based A* path finding routine in a continuous game world There may be tradeoffs to consider (e.g. compromising behavior quality)
11
11 Handling Movement The allowed movement is imposed on the creatures by their environment In both 2D and 3D worlds the patter is: Game simulation loop Integration Collision detection
12
12 Role of Game Engine Game engine takes into account all movement requests from players and NPC ’ s Physics system resolves all collisions and updates the creature data structures with new velocities, positions, and orientations Animation system handles low-level “ limb ” control as predefined animations (abstracting this low-level control as a “ locomotion ” layer greatly simplifies programming)
13
13 Dr. Spin (Animat) #include "Brain.h" using namespace fear; void SpinBrain::Think() // call when the animat need to think { motion->Move( Motion::Forward ); motion->Turn( 15.0f ); } // Think() SpinBrain::SpinBrain() // Initialization : SpinBrainBase(), Architecture("SpinBrain") { } // SpinBrain() SpinBrain::~SpinBrain() { } // ~SpinBrain()
14
14 Dr. Spin Only behavior is to move and turn Often bumps into walls Can get stuck in corners Supposed to demonstrate the importance of world simulation and structure on movement
15
15 Navigation - 1 Process of purposely steering course of some entity though a physical environment Autonomous navigation means the software system can steer its course unassisted Navigation produces proactive rather than reactive movement Purposeful navigation is not possible by trial and error of actions
16
16 Navigation - 2 Most living creatures require spatial information to interpret that provides them a sense of their world and helps them select their “ next step ” Much of the complexity of navigation comes from the acquisition of world information A rough description of space is encoded by animals to help them pick out empty and solid spaces
17
17 Game Bots - 1 Very few computer games use sensing and environment interpretation to achieve navigation behavior Virtual game worlds can be stored entirely in the computer ’ s memory Algorithms process the world description to extract structural information form it
18
18 Game Bots - 2 The bot is part of the game simulation world so they have perfect position information By dropping waypoints or processing polygons a compact terrain description can be given to the bot before the game begins Bots are particularly good at global movement and allow very effective use of standard algorithms like A*
19
19 Game Bots - 3 Bots do not sense the world like animals Bots perceive the world using preprocessed environment knowledge and this is not always good The terrain model might be based on erroneous assumptions The terrain model may not be up to date in dynamic environment Bots can become stuck or ignore obstacles
20
20 Animats Autonomous navigation is possible by giving animats the ability to sense the environment and selectively process the relevant information This give animats fresh information about their local surroundings This reactive approach has good local navigation, but has problems reaching points in space (similar to hill climbing)
21
21 Criteria for Effective Motion Realistic Movement must be similar to real world analogs Efficient Economical use of processing cycles Reliable Must guarantee NPC can complete standard situations with getting stuck Purposeful Must be able to achieve goals in space
22
22 Motion Tradeoffs These criteria often comes in conflict with one another and compromise is needed Efficiency has historically been the greatest concern of game developers Realism has become more important in recent years Different game situations require different tradeoff decisions
23
23 Obstacle Avoidance With no obstacles near, animat is free to travel in any direction With walls on one side, animat should be turned away slowly in a preventative manner With obstacle in front, turn should be executed to avoid danger on one side When stuck in a corner, animat should attempt a complete turnaround
24
24 Bouncer (Animat) void BouncerBrain::Think() { Vec3f moved, turned; // determine how far the body moved since the last update physics->GetMovement( moved ); // query the physics sensor for relative movement physics->GetOrientation( turned ); // check recent body rotation too // Check if the forward movement was less than expected, indicating a collision. // Ideally 100%, but less than 75% is a good measure that's not overly precise. if (moved.x < 0.75f * k_StepSize) { // In this case, we can assume an obstacle of some sort. // The impact may have forced the body to turn in a particular direction. // Use the yaw of the last forced turn to determine the direction to turn in turn = turned.y < 0.0f ? -30.0f : 30.0f; // request a turn of magnitude 30 degrees either left or right motion->Turn( turn ); } // by default always try to move forward motion->Move( Motion::Forward ); } // Think()
25
25 Bouncer Runs around the game monitoring its own movement If its forward movement is not what was expected, a collision is assumed Following a collision, animat takes off in a random direction until it can move again
26
26 Pattern Movement Give the illusion of intelligent behavior NPCs move according to predefined patterns that appear as performing complex, thought-out actions Standard method for implementing pattern movement takes the desired pattern and encodes the control data (e.g., turns and moving steps) into sets of arrays / vectors Easy to implement in tile-based environment In physically simulated environment, the steering control does the task. However, the physics engine and model itself have its restriction (e.g. speed, turning radius and etc.)
27
27 Enhancements Wandering Make random behavior appear a little more purposeful Patterns should be slightly unpredictable, but not arbitrarily random Could accumulate steering values and filter them using the sin function (gives both + and – values)
28
28 Game Copyright Statement for Animats /******************************************************************************************** * AI Game Development: Learning & Reactive Behaviors * * Copyright (c) 2002-2003 Alex J. Champandard, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it under the terms * of the GNU General Public License (GPL) as published by the Free Software Foundation. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the attached LICENSE file for details. * ********************************************************************************************/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.