30
Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

Embed Size (px)

Citation preview

Page 1: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

Steering Autonomous Characters

Spring 2005

Ref: Craig Reynolds

Page 2: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

2

Introduction-1 Autonomous characters: also known as NPC

(non-player character) in games Steering: the ability to navigate around their

world in a life-like and improvisational manner.

Page 3: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

3

Introduction-2 Motion-behavior hierarchy [herding example]

Page 4: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

4

Herding Example

some cowboys tending a herd of cattle out on the range. A cow wanders away from the herd. The trail boss tells a cowboy to fetch the stray. The cowboy says “giddy-up” to his horse and guides it to the cow, possibly

avoiding obstacles along the way.

Action selection: the trail boss, noticing that the state of the world has changed (a cow left the herd) and setting a goal (retrieve the stray).

The steering level: the cowboy, who decomposes the goal into a series of simple subgoals (approach the cow, avoid obstacles, retrieve the cow). A subgoal corresponds to a steering behavior for the cowboy-and-horse team. Using various control signals (vocal commands, spurs, reins) the cowboy steers his horse towards the target. In general terms, these signals express concepts like: go faster, go slower, turn right, turn left, and so on.

The horse implements the locomotion level. Taking the cowboy’s control signals as input, the horse moves in the indicated direction. This motion is the result of a complex interaction of the horse visual perception, its sense of balance, and its muscles applying torques to the joints of its skeleton.

Page 5: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

5

Introduction-3 Path-finding is a topic related

to, but separate from, the subject of this paper.

Path-finding algorithms such as A* and Dijkstra's operate on networks (often representing grids) and essentially solve mazes.

Such a solution could serve as a specification to the steering techniques described in this paper.

Steering behaviors discussed here relate to “fast” motion: running versus crawling.

As a result, the steering behaviors must anticipate the future, and take into account eventual consequences of current actions.

The approach taken in this paper is to consider steering behaviors as essentially independent from the underlying locomotion scheme.

Page 6: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

6

Vehicle: Idealized locomotion model based on a point mass approximation. The physics is based on forward Euler integration.

the control signal passed from the steering behaviors to the locomotion behavior consists of exactly one vector quantity: a desired steering force.

Because of its assumption of velocity alignment, this simple vehicle model cannot simulate effects such as skids, spins or slides.

Page 7: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

7

Supplemental

dt

dxv

dt

dva

maf

,

:physics From

mtfta

ttatvttv

ttvtxttx

t

/

smallfor y,Numericall

To get t between displays:

int glutGet (GLUT_ELAPSED_TIME) : msec

Page 8: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

8

Vehicle: 3D vs. 2D

Airplane vs. ground vehicle Velocity aligned frame: 3

axes: forward, up, and side. Use rotation-minimizing

frame (next page) to update the character local frame

forward(v)

side

up

Page 9: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

9

Rotation Minimizing Frame (ref)

Use second derivative to define the first frame (if zero, set N0 to any vector T0)

Compute all subsequent Ti; find a rotation from Ti-1 to Ti; rotate Ni and Bi accordingly If no rotation, use the same

frame

Page 10: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

10

Building Blocks of Steering

Seek/Flee Pursuit/Evasion Arrival Obstacle avoidance Wander Path following Containment Flow field following

Unaligned collision avoidance

Group: separation, cohesion, alignment

Combined behavior

application; implementation

Offset pursuit

Page 11: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

11

Seek/Flee & Arrival The length of “desired velocity”

could be max_speed, or it could be the character’s current speed, depending on the particular application.

Arrival: velocity ramp down (linearly) to zero while approaching target

Application: stop for traffic light Does not produce a steering

force; rather, it sets up a flag for velocity modification

Page 12: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

12

Pursuit/Evasion Chasing moving target: use

a simple predictor and reevaluate it each simulation step.

linear predictor: assuming that the target will not turn during the prediction interval, T

The position of a character after T units of time can be obtained by scaling its velocity by T and adding that offset to its current position.

Page 13: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

13

Pursuit (cont) T could be a constant,

which while naive, would produce better pursuit than simple seek (T=0).

For better performance, T should be larger when the pursuer is far from the target, and small when they are nearby.

T=Dc where D is the distance between pursuer and quarry, and c is a tuning parameter.

Page 14: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

14

Offset Pursuit … refers to steering a path

which passes near, but not directly into a moving target.

Examples would be a spacecraft doing a fly-by or an aircraft doing a “strafing run”: flying near enough to be within sensor or weapon range without colliding with the target.

Set target point, use seek steering

Page 15: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

15

Collision Avoidance The goal of the behavior is to keep

an imaginary cylinder of free space in front of the character Diameter: the character’s

bounding sphere Length: based on the

character’s speed Exhaustive search or spatial

partitioning to help identify the candidate obstacles Generally only care about

obstacles which are between us and our goal.

Corrective steering: consider the most threatening obstacle, take its projection on side-up plane

B is most threatening

Page 16: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

16

Collision Avoidance (cont) 3D projection (on side-up

plane) to predict future collision

Page 17: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

17

Wander: random steering Rather than truly random, retain steering direction state and

make small random displacements to it each frame Another way to implement wander would be to use coherent

Perlin noise [Perlin 85] to generate the steering direction

Page 18: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

18

Wander (Illustrated-1)

Generate a wander in green circle

New steering direction

Page 19: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

19

Wander (Illustrated-2)

Steering direction updated

Page 20: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

20

Path Following

a path will be idealized as a spine and a radius. The spine might be represented as a spline curve or a poly-line

velocity-based prediction The predicted future position is

projected onto the nearest point on the path spine.

If the character is veering away from the path, or is too far away from the path, apply corrective steer.

To steer back towards the path, the seek behavior is used to steer towards the on-path projection of the predicted future position.

Wall following: path following + offset pursuit

Examples of containment: fish swimming in an aquarium; hockey players skating within an ice rink.

Page 21: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

21

Flow Field Following

useful tool for directing the motion of characters based on their position within an environment.

Flow field designed by a level designer (game production) or a scene planner or layout artist (animation production).

Page 22: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

22

Unaligned Collision Avoidance

Consider your own experience of walking across a plaza or lobby full of other walking people: avoiding collisions involves predicting potential collisions and altering your direction and speed to prevent them

If all nearby characters are aligned, use separation.

Page 23: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

23

Unaligned Collision Avoidance

Our character considers each of the other characters and determines (based on current velocities) when and where the two will make their nearest approach. A potential for collision exists if the nearest approach is in the future, and if the distance between the characters at nearest approach is small enough.

The nearest of these potential collisions, if any, is determined.

Steering strategy: turning, change speed

Page 24: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

24

Group Steering (cont)

How character reacts to other characters in its neighborhood

Stampede scene in Lion King

Nbhd definition

Page 25: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

25

Corrective Steering-1

Compute difference vector between character and each one in the neighborhood; then apply 1/r weighting.

Apply seek towards “average position” of neighbors

Page 26: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

26

Corrective Steering-2

Desired velocity determined by average of neighbors

unit vector or not depends on applications

Combining Behaviors For better control it is

helpful to first normalize the three steering components, and then to scale them by three weighting factors before summing them.

Tuning parameters: Weights, nbhd def

(distance, angle)

Page 27: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

27

Compound Steering The implementation of

leader following relies on arrival behavior. The arrival target is a point offset slightly behind the leader. (The offset distance might optionally increases with speed.)

If a follower finds itself in a rectangular region in front of the leader, it will steer laterally away from the leader’s path before resuming arrival behavior.

In addition the followers use separation behavior to prevent crowding each other.

Page 28: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

28

Other Applications

Interpose steering behavior attempts to put its character between two other moving characters, for example a soccer player trying to block a pass between two members of the opposing team.

Hide behavior involves identifying a target location which is on the opposite side of an obstacle from the opponent, and steering toward it using seek.

building blocks for more complex patterns of behavior. like notes of a melody or words of a story.

Page 29: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

29

Combining Behavior

Two modes: switching or blending Example 1: imagine caribou grazing in a meadow

when suddenly they sense wolves approaching. This event triggers a discrete behavioral switch.

take place at the action selection level

Example 2: As the caribou flee through the forest, they blend evasion and obstacle avoidance together to allow them to escape from the wolves while dodging trees.

occurs at the middle steering level of the behavioral hierarchy.

Page 30: Steering Autonomous Characters Spring 2005 Ref: Craig Reynolds

30

Blending Concerns and Strategy

Minimize computation cost by considering character momentum; avoid canceling steering output

Prioritize steering (e.g., collision avoidance > evasion > …)

Simple linear combination might do just fine