7 . 2. ai engine and steering behaviour i

20
7.2. AI ENGINE AND STEERING BEHAVIOUR I Design of an AI Engine and introduction to steering in game AI

Upload: stacy

Post on 15-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

7 . 2. AI Engine and Steering Behaviour I. Design of an AI Engine and introduction to steering in game AI. Game AI Engine. Design of a game Artificial Intelligence Engine. A Game Artificial Intelligence Engine. - PowerPoint PPT Presentation

TRANSCRIPT

7.2. AI Engine and Steering Behaviour IDesign of an AI Engine and introduction to steering in game AI

1Game AI EngineDesign of a game Artificial Intelligence Engine

2A Game Artificial Intelligence EngineIn simple games, AI tends to be bespoke and individually written for each character (e.g. embedded within the layer/object update method).In more complex games there is a need to have a set of general AI routines that can be controlled by level designers, etc. There is often a need to manage CPU/memory constraints.

Aside: Unless you explicitly wish to do so, you do not need to define a separate AI engine in your relatively simple game.

3Example structure of an AI EngineThe AI gets some time to perform / progress its routines.Higher-level AI applies to groups, whilst lower-level AI operates on individual game objects.The AI engine can query the world to obtain information.The output of the AI engine is turned into actions that update the game state.

AI receives processor timeAI output is turned into actionAI obtains world informationAside: Not all games need all types of AI, e.g. Board games may only need strategic AI, whilst a scrolling shooter may only need simple movement AI.

The example game engine design in this section is based on that defined within Artificial Intelligence for Games (Ian Millington, 2008)4AI Engine (movement)The movement component contains a range of algorithms that make decisions about motion.There are a range of movement algorithms, from very simple, to very complex.

5AI Engine (decision making)Each game character will typically have a range of different behaviours that can be performed. The decision making process determines which behaviour is best at a given point in time.Selected behaviours are then translated into action (possibly making use of movement AI, or simply triggering an animation).

6AI Engine (strategy)In order to coordinate the behaviour of multiple game objects some form of strategic AI is often needed.In other words, strategic AI controls/ influences the behaviour of a group of characters, often devolving the execution of the group behaviour to individual decision making / movement algorithms.

7Introduction to MovementIntroduction to the different forms of movement AI

8Introduction to movement AIThe aim of movement AI is to sensibly move game objects around the level.All movement algorithms take as input data about the state of the world and output geometric data about the desired form of movement.Some algorithms only require the objects position and a target position. Others algorithms require lots of interaction with objects (e.g. collision avoidance, etc.).Some algorithms directly output a new velocity (termed kinematic movement), others output an acceleration/force used to update the objects velocity (termed dynamic or steering behaviours)

They are termed steering behaviour based on the work of Craig W. Reynold, an a-life expert who famously created the Boids a-life simulation9

Introduction to movement AI (kinematics)All game objects can be defined as having a position and an orientation.In some game types a movement algorithm can directly update the position/orientation (e.g. tile-based). However, this will look unrealistic in other types of game (e.g. driving).In order to permit continuous (2D) movement it is necessary to store:

Vector positionfloat orientation;Vector velocity;float rotation;Steering algorithms output an acceleration (or force) applied to directional or rotational velocities. Using the Newton Euler equations, the variables can be updated as follows:

velocity += acceleration * time_deltarotation += angular_acc * time_delta

position += velocity * time_deltaorientation += rotation * time_deltaAside: In most 3D games, characters are usually under the influence of gravity, with movement effectively constrained to just two dimensions

10Kinematic Movement AlgorithmsBasic forms of kinematic movement algorithm

Based upon Artificial Intelligence for Games

11Kinematic movement algorithmsKinematic movement algorithms operate using positions and orientations. The output is a target velocity (speed + orientation).The speed may simply vary between full speed and stationary, i.e. kinematic algorithms do not use acceleration.This section will explore the following basic forms of kinematic movement algorithm:

Seek()Flee()Arrive()

To do:Consider if applicable

12SeekSeek takes as input a current and target location. The algorithm calculates the direction from the current to the target location and defines a matching velocity. The velocity can be used to define the output orientation if needed.

Seek ( Vector source, Vector target,float maxSpeed ) {

Vector velocity= (target source).normalise()* maxSpeed;return velocity;}DetermineOrientation(Vector velocity, float currentOrientation ) {

if( velocity.length() == 0 )return currentOrientation;elsereturn Math.atan2( -velocity.x, velocity.y)}Current velocityTarget velocitynormalise() will return vector of unit length and same directionSee common on next slide for atan

13FleeFlee is the opposite of Seek, i.e. the object moves away from their target. It can simply be defined as the opposite of the velocity returned by Seek, i.e:

Flee( Vector source, Vector target,float maxSpeed ) {

Vector velocity= (source target).normalise()* maxSpeed;return velocity;}Aside: Why atan2 on last slide? atan2 computes the arctangent of y/x in a range of (, ), i.e. it determines the counter clockwise angle (radians) between the x-axis and the vector in 2D Euclidean space. The normal atan function returns a range of (/2, /2)

This is useful to find the direction from one point to another.

14ArriveA problem with Seek is that it can keep overshooting the target, never reaching it. One means to overcome this is to provide a buffer close enough region around the target. Another is to reduce the speed as the target comes close. Both approaches can be combined as follows:

Arrive ( Vector source, Vector target,float maxSpeed, float nearRadius ) {

float slowingFactor = 0.2;

Vector velocity = [0,0,...];Vector separation = (target source);

if( separation.length() < nearRadius )return velocity;velocity = separation / slowingFactor;if( velocity.length() > maxSpeed )velocity = velocity.normalise() * maxSpeed;return velocity;}vel = maxvel= maxvel= max * 0.75vel= max * 0.6vel= max * 0.4Closeness thresholdAside: As with seek, etc., the returned velocity can be used to provide the objects orientation if desired.slowingFactor = slowing strengthDetermine velocity, and cap at max speed if neededReturn initial velocity = 0.0

15Steering Movement AlgorithmsForms of dynamic (or steering) movement algorithm

Based upon Artificial Intelligence for Games

16

Steering movement algorithmsSteering behaviours extend the kinematic movement algorithms by determining acceleration (both forward movement and rotation)In many game types (e.g. driving games) steering algorithms are often used. In other games, they may not be useful.We will consider the following forms of steering behaviour:Seek()Flee()Arrive()Wander()

To do:Consider if applicableFace()Separate()PathFollow()AvoidObstacle()Jump()Pursue()Evade() Interpose()Align()

17Matching a target propertyBasic steering algorithms operate by trying to match some kinematic property of the target to the source, e.g. this might be the targets position, velocity, orientation, etc. Matching steering algorithms take source and target kinematic properties as input.More advanced steering behaviours try to match a combination of properties, potentially with additional constraints.Typically for each matching behaviour there is a readily defined opposite behaviour (e.g. Seek vs. Flee, etc.).

Flee pathSeek path

18Thinking about movement.The next lecture will consider the steering behaviours in detail.As part of completing the Question Clinic for this week, please do think about the role of AI (including movement based AI) in your game and identify current areas of uncertainty.

To do:Think about movement

19

Summary

To do:Complete Question ClinicIterate/refine your game design to define AI needsContinue to plan what you hope to do for the Alpha handinToday we explored:

The design of an AI engineKinematic forms of movement AIIntroduction to steering forms of movement AI

20