View
220
Download
0
Category
Preview:
DESCRIPTION
High Level Some ‘meta’ intelligence decides it is time to flee Ex: Rule: if badguy.size > me.size How do we implement fleeing?
Citation preview
CSCI 4310Lecture 5: Steering Behaviors in Raven
Book Buckland Chapter 3, 7
Generating Automated Agent Behavior
High Level Some ‘meta’ intelligence decides
it is time to flee Ex: Rule: if badguy.size >
me.size
How do we implement fleeing?
Background Vectors
v(6,2)
Magnitude= √(6² + 2²)= |v|= 6.32
Also called norm
Vector v(6,2)
Background Normalize Vectors
xN = x / |v|
xN = 6 / 6.32
yN = y / |v|
yN = 2 / 6.32
New Magnitude = 1Direction unchanged
Background
cos(Θ) = ay / |v|Θ = arccos (ay / |v|)ay = |v| cos (Θ)
sin(Θ) = ax / |v|Θ = arcsin (ax / |v|)ax = |v| sin (Θ)
Component Vectors
x
y Θ v
a
Background
Dot product of 2 vectorsu, v
u · v = |u||v| cos (Θ)normalize u, vu · v = cos (Θ)Θ = arccos (u · v)
Dot product
x
y Θ v
a
Dot product of 2 vectorsu, v
u · v = uxvx + uyvy
Angle between vectors
RavenVector2D struct has methods for
Normalizing, Dot product, and adding, multiplying, etc. vectors
Steering: Seek Direct our player
toward a target position
Return a force (Vector) to a target position
Airplane navigation
Steering: Seek
current
target
Steering force (seek)
Desired = targetPos – vehiclePosAssume vehicle at (0,0)Desired = (5,6)Current + = Desired
desired
Steering: Seek Vector2D SteeringBehaviors::Seek(Vector2D TargetPos)
Vehicles contain a reference to a SteeringBehaviors
SteeringBehaviors::Seek returns a Vector2D
Returned Vector2D represents the steering force
Seek demo
Steering: Flee Run away from a given position
Return a force (Vector) to a target position
Opposite of seek
Modified in book p. 92 to flee only when a target is within a certain range
Steering: Flee
current
target
Steering force (flee)
Desired = vehiclePos – targetPosAssume vehicle at (0,0)Desired = (-5,-6)Current + = Desired
desired
Steering: Flee Vector2D SteeringBehaviors::Flee(Vector2D TargetPos)
Returned Vector2D represents the steering force
Flee demo
Steering: Arrive Vector2D SteeringBehaviors::Arrive(Vector2D TargetPos, Deceleration decel)
Arrive allows you to seek and come to a slower arrival (based on deceleration parameter)
Deceleration is an enumeration, slow=3, normal=2, fast=1
Steering: Arrive Just adjust speed multiplier
(magnitude) of DesiredVelocity vector to slow down
Base on distance to target Arrive demo
Steering: Pursuit
Intercepting a moving target Don’t just aim for the target
position Aim for where you *think* the
target will be Look-ahead directly proportional
to distance to evader and inversely proportional to speed
Another modification of seek
Steering: Pursuit Vector2D SteeringBehaviors::Pursuit(const Vehcile* evader)
Seek (evader->Pos() + evader->Velocity * LookAheadTime)
LookAheadTime = ToEvader.Length() /me->MaxSpeed() + evader->Speed()
Steering: Pursuit
currentevader
Steering force (flee)
Current + = Desired
desired
current
Pursuit Demo
Steering: Evade Vector2D SteeringBehaviors::Evade(const Vehcile* pursuer)
Opposite of pursuit:
Evader flees from the estimated future position.
Steering: Evade Flee (persuer->Pos() +
persuer->Velocity * LookAheadTime)
LookAheadTime = ToPersuer.Length() /me->MaxSpeed() + persuer->Speed()
Steering: Wander Steering force for a ‘random walk’ Just moving randomly is unconvincing
and erratic No one out on a walk stops and
reverses course frequently
Perlin noise – Ken Perlin (Tron) Remember our earlier statement: Randomness can make us look
smarter!
Steering: Wander
One solution: Project a circle in front of the agent Steer towards a target that is
constrained to move along the perimeter of this circle
Target adjusts in small increments along the perimeter
Adjust algo based on circle radius, target adjustments, circle distance
Steering: Wander
wander radius
wander distance
Wander Demo
Steering: Obstacle Avoidance Need concept of a
bounding box (or detection box)
Rather than detecting a collision on a complex boundary
Can get incrementally more detailed in collision detection
Steering: Obstacle Avoidance Collision detection is a
detailed endeavor Only recently
distinguished hits by location in FPS
Steering: Obstacle Avoidance
Detection boxlength proportionate to speed
obs
Dot product of agent (purple) vector and vector to obstacle will be positive if obs is in front – this obstacle can be ignored.
Steering: Obstacle Avoidance
obs obs
Extend obstacle boundary by ½width of detection box. If newboundary crosses agent vector,collision occurs at intersection ofnew boundary and detection box.
Steering: Obstacle Avoidance
obs
obs
Steering: Obstacle Avoidance Vector2D
SteeringBehaviors::ObstacleAvoidance(const std::vector<BaseGameEntity*> &obstacles)
Once an obstacle that will cause a collision is detected, need a steering force to avoid.
Just like driving: slow down and avoid
Steering: Obstacle Avoidance Lateral force in proportion to
obstacle’s position with respect to the agent
Braking force in proportion to distance to obstacle (force acting along opposite vector of agent)
Code omitted
Obstacle Avoidance Demo
Steering: Hide
Position yourself such that an obstacle is always between you and an agent
Constant (c) for distance from obstacle
c
‘Arrive’ to this position
Steering: Hide Vector2D SteeringBehaviors::Hide(const Vehicle*
target, vector<BaseGameEntity*>& obstacles)
For Each Obstacle Calculate A hiding position for this
obs Calculate Distance to hiding position
Is Hiding Position Available? Yes – Call ‘Arrive’ to Closest No – Evade
Hide Demo
Steering: Path Following Useful for creating botbehaviors such as patrolling
Used for multi-stage navigation
Very commonly used in most games Some other function determines a
goal location – more difficult Calls FollowPath to get there
Steering: Path Following Vector2D SteeringBehaviors::followPath( )
Just ‘seek’ each waypoint in turn Can ‘arrive’ at final destination
Path object in GameWorld class
Path class omitted
Path Following Demo
Steering: Group Behavior
Agents can react to other agents Multi-agent aware
From our earlier discussion of environment and agent attributes
Mimic nature Simple creatures performing complex
activities - ACO Neighborhood – pervasive concept.
What is the sphere of influence? This idea present in many AI concepts
Steering: Flocking Combination of
Separation Alignment Cohesion
Flocking Demo
Recommended