1 / 37

CSCI 4310

CSCI 4310. Lecture 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. Vector v(6,2).

hutchinsh
Download Presentation

CSCI 4310

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Vector v(6,2) v(6,2) Magnitude = √(6² + 2²) = |v| = 6.32 Also called norm

  5. Background • Normalize Vectors New Magnitude = 1 Direction unchanged xN = x / |v| xN = 6 / 6.32 yN = y / |v| yN = 2 / 6.32

  6. Background Component Vectors v y Θ x a cos(Θ) = ay / |v| Θ = arccos (ay / |v|) ay = |v| cos (Θ) sin(Θ) = ax / |v| Θ = arcsin (ax / |v|) ax = |v| sin (Θ)

  7. Background Dot product of 2 vectors u, v u · v = uxvx + uyvy Dot product v y Θ x a Dot product of 2 vectors u, v u · v = |u||v| cos (Θ) normalize u, v u · v = cos (Θ) Θ = arccos (u · v) 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 desired Steering force (seek) Desired = targetPos – vehiclePos Assume vehicle at (0,0) Desired = (5,6) Current + = 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 Desired = vehiclePos – targetPos Assume vehicle at (0,0) Desired = (-5,-6) Current + = 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 current Steering force (flee) desired Current + = Desired 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 Demo wander radius wander distance

  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 Dot product of agent (purple) vector and vector to obstacle will be positive if obs is in front – this obstacle can be ignored. obs Detection box length proportionate to speed

  28. obs Steering: Obstacle Avoidance Extend obstacle boundary by ½ width of detection box. If new boundary crosses agent vector, collision occurs at intersection of new boundary and detection box. obs

  29. obs Steering: Obstacle Avoidance obs

  30. 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

  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 ‘Arrive’ to this position c

  33. 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

  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

More Related