Download presentation
Presentation is loading. Please wait.
1
CSCI 4310 Lecture 5: Steering Behaviors in Raven
2
Book Buckland Chapter 3, 7 Generating Automated Agent Behavior
3
High Level Some ‘meta’ intelligence decides it is time to flee Ex: Rule: if badguy.size > me.size How do we implement fleeing?
4
Background Vectors v(6,2) Magnitude = √(6² + 2²) = |v| = 6.32 Also called norm Vector v(6,2)
5
Background Normalize Vectors x N = x / |v| x N = 6 / 6.32 y N = y / |v| y N = 2 / 6.32 New Magnitude = 1 Direction unchanged
6
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
7
Background Dot product of 2 vectors u, v u · v = |u||v| cos (Θ) normalize u, v u · v = cos (Θ) Θ = arccos (u · v) Dot product x y Θ v a Dot product of 2 vectors u, v u · v = u x v x + u y v y Angle between vectors
8
Raven Vector2D struct has methods for Normalizing, Dot product, and adding, multiplying, etc. vectors
9
Steering: Seek Direct our player toward a target position Return a force (Vector) to a target position Airplane navigation
10
Steering: Seek current target Steering force (seek) Desired = targetPos – vehiclePos Assume vehicle at (0,0) Desired = (5,6) Current + = Desired desired
11
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
12
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
13
Steering: Flee current target Steering force (flee) Desired = vehiclePos – targetPos Assume vehicle at (0,0) Desired = (-5,-6) Current + = Desired desired
14
Steering: Flee Vector2D SteeringBehaviors:: Flee(Vector2D TargetPos) Returned Vector2D represents the steering force Flee demo
15
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
16
Steering: Arrive Just adjust speed multiplier (magnitude) of DesiredVelocity vector to slow down Base on distance to target Arrive demo
17
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
18
Steering: Pursuit Vector2D SteeringBehaviors:: Pursuit(const Vehcile* evader) Seek (evader->Pos() + evader->Velocity * LookAheadTime) LookAheadTime = ToEvader.Length() / me->MaxSpeed() + evader->Speed()
19
Steering: Pursuit current evader Steering force (flee) Current + = Desired desired current Pursuit Demo
20
Steering: Evade Vector2D SteeringBehaviors:: Evade(const Vehcile* pursuer) Opposite of pursuit: Evader flees from the estimated future position.
21
Steering: Evade Flee (persuer->Pos() + persuer->Velocity * LookAheadTime) LookAheadTime = ToPersuer.Length() / me->MaxSpeed() + persuer->Speed()
22
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!
23
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
24
Steering: Wander wander radius wander distance Wander Demo
25
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
26
Steering: Obstacle Avoidance Collision detection is a detailed endeavor Only recently distinguished hits by location in FPS
27
Steering: Obstacle Avoidance Detection box length 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.
28
Steering: Obstacle Avoidance obs Extend obstacle boundary by ½ width of detection box. If new boundary crosses agent vector, collision occurs at intersection of new boundary and detection box.
29
Steering: Obstacle Avoidance obs
30
Steering: Obstacle Avoidance Vector2D SteeringBehaviors::ObstacleAvoidance(const std::vector &obstacles) Once an obstacle that will cause a collision is detected, need a steering force to avoid. Just like driving: slow down and avoid
31
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
32
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
33
Steering: Hide Vector2D SteeringBehaviors::Hide(const Vehicle* target, vector & 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
34
Steering: Path Following Useful for creating bot behaviors 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
35
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
36
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
37
Steering: Flocking Combination of Separation Alignment Cohesion Flocking Demo
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.