1 / 56

Steering Behaviours

Steering Behaviours. Robin Green Sony Computer Entertainment Robin_Green@playstation.sony.com. Definitions. Vehicle The abstract representation of a moving object. Behaviour Code that generates a steering force each iteration. The Vehicle Object. The Vehicle Object.

thomasinam
Download Presentation

Steering Behaviours

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. Steering Behaviours Robin Green Sony Computer Entertainment Robin_Green@playstation.sony.com

  2. Definitions • Vehicle • The abstract representation of a moving object. • Behaviour • Code that generates a steering force each iteration.

  3. The Vehicle Object

  4. The Vehicle Object • A vehicle is represented in this tutorial by a circle in 2D space or sphere in 3D. • Diagrams will use triangles or circles (with correct extent) with velocity vector.

  5. A vehicle must have: position velocity radius set of behaviours maximum force maximum velocity Optional extras: mass orientation local reference frame target references formation position The Vehicle Object

  6. A Basic Vehicle class Vehicle {public: void update();public: BehaviourList list; float mass; Vector2d pos; Vector2d vel; float max_force; float max_speed;};

  7. Integration • Euler Integration • Not accurate, not elegant but fast.

  8. Clamping Forces • Clamp the vector length of forces to max_force and max_speed.

  9. Updating The Vehicle • The ratio of max_force to max_speed will control 1. Time it takes to get to max_speed 2. Turning circle radius (rate of change of direction) 3. Stopping speed (rate of change of speed) 4. Accuracy of hitting targets

  10. Updating The Vehicle void Vehicle::update() { Vector2d force(0,0); BehaviourList::iterator i; for(int i=list.begin(); i!=list.end(); ++i) { force += i->calculate(); } Vector2d steering = truncate(force,max_force); Vector2d acc = steering / mass; vel += truncate(vel + acc, max_speed); pos += vel;}

  11. Behaviours

  12. Seek & Flee Pursue & Evade Arrival Offset Pursuit Formations Obstacle Avoidance Separation Follow Path Avoid Walls Wander Follow Flow Field Interpose & Hide Collision Avoidance Flocking Behaviours

  13. Designing Behaviours • Generate a desired velocity • Calculate from the current state where the vehicle should be going. • Calculate the steering force • Calculate the difference between current and desired velocities: steering = desired - vel;

  14. steering steering pos target Seek & Flee • Seek • Flee vel desired =normalise(target-pos) * max_speed;steering = desired - vel; desired =normalise(pos-target) * max_speed;steering = desired - vel;

  15. Predict target position Maybe using distance to target and time to turn. Seek that position steering steering desired Pursue & Evade predicted predict = target.pos + time * target.vel; desired = normalise(predict - pos) * max_speed;steering = desired - vel;

  16. How fast do we need to go to get to the target in decel_time units of time? Arrival steering dist = length(target-pos);speed = min(distance/decel_time, max_speed);desired = normalise(target-pos) * speed;steering = desired - vel; desired max_speed <max_speed

  17. Move through a point adjacent to a target Find target in local space. Convert target to world space. Seek target position. Offset Pursuit

  18. Seek a position defined by a Leader’s local-space formation. Find target in Leader’s local space. Convert target to world space. Seek target position. Formation

  19. Causes vehicles to follow a smoothed random path. In local space, construct a circle in front of the vehicle. Pick a target point on the circle. Add a random vector to the target position, then reproject the target onto the circle. Project the target into world space. Seek the target point. Wander

  20. Force vehicles to use space more realistically. Search world for neighbours within a search radius. For each neighbour, calculate and accumulate a 1.0/distance2 repelling force. Truncate resulting vector to max_force Separation

  21. Keep a box in front of the vehicle free of obstacles. Search world for collision candidates. Project their positions into local space. In local space, choose closest obstacle to steer away from. Generate lateral steering force. Project steering force back into world space. Avoid Obstacle

  22. Avoid Obstacle Tweaks • In addition: • Scale length of box w.r.t. velocity (anticipating obstacles). • Scale repelling force w.r.t. distance from vehicle (steering more to avoid close obstacles). • Add small negative amount of velocity proportional to distance from vehicle (vehicle brakes to steer).

  23. Follow Path • Three strategies for path following: 1. Dog On A String 2. Reprojections 3. Grappling Hooks.

  24. destination waypoint current waypoint waypoint subpath Parts Of A Path • A path is a polyline of “waypoints”. • Each line between waypoints is a “path segment”. • A collection of path segments is a “subpath”

  25. Linearly interpolate a target point down the polyline. Measure distance from vehicle to target to calculate the target increment. Seek the target point. Dog On A String

  26. Calculate the vehicle’s position in the near future. Project that future position onto the path. Use “closest point on line to point” calculation. Seek that projected position. In effect keeping the vehicle within a wide stroke path. Reprojection

  27. Starting with the first waypoint, keep a note of the “current waypoint”. Seek the current waypoint. If distance to current < threshold, increment current. NOTE: Only works on line-of-sight paths. Grappling Hook

  28. Predict the vehicle’s future position. If future pos intersects a wall Reproject the future position onto the wall surface along the surface normal. Extend this reprojection vector. Seek the target point. Else return no steering vector. Avoid Walls

  29. Predict your vehicle’s position forward in time. Look up the desired velocity from the flow field map. You may like to bilinear filter the value from surrounding samples for smoothness. Follow Flow Field steering = flow_field[x,y] - vel;

  30. Interpose Seek a target halfway along the vector between two objects. Hide Pick a point inside the occluding object. Seek a target extended beyond that point. Interpose & Hide

  31. One of the more complicated behaviours. Picture two groups of vehicles passing through each other at a crossroads, each vehicle avoiding collisions. Three parts to this behaviour: 1. Neighbour search. 2. Find Closest Approach. 3. Take Evasive Action Unaligned Collision Avoidance

  32. 1. Neighbour Search. Important to set an upper bound on the search area. Vehicles probably won’t be travelling in a straight line for too long. Search returns a set of “collision candidates” for further tests Ideal search area (assuming constant velocity) Approximated search area. Unaligned Collision Avoidance

  33. 2. Find closest approach Find the one candidate that will collide soonest assuming constant velocity. v v p p |v| = 0 p p v Unaligned Collision Avoidance p = B.pos - A.posv = B.vel - A.vela = v.pb = v.vtime = - a / bdist_sq = p.p + 2*a*time + b*time*time

  34. 3. Take Evasive Action Vehicles can speed-up/brake and they can turn to avoid. How to choose? Avoiding Strategy: If one vehicle has extra velocity, speed up. If vehicles both are at max_speed, choose one to brake and turn. If distance > threshold, both vehicles turn. etc... Unaligned Collision Avoidance Steering to avoid collision

  35. Flocking • The “Boids” flocking algorithm is comprised of three concurrent behaviours: 1. Separation 2. Cohesion 3. Alignment

  36. Covered earlier. The 1/r2 repelling force isn’t intrinsic and can be replaced with a different scaled force for interesting effects. Separation

  37. Vehicles in the same area tent towards the mean point. This forces vehicles on the outside to bind together into flocks rather than fly off independently. For each vehicle, search for neighbours, calc. the mean position and seek that point. Cohesion

  38. Vehicles in the same area tend to face the same direction. This forces flocks to swirl as direction changes propogate through the flock. For each vehicle, search for neighbours, calc. the mean facing direction, add in correcting force. Alignment

  39. Combining Behaviours

  40. Types of Behaviour • Constant Forces • Behaviours that produce a force every iteration • e.g. Follow Path, Follow Flow Field, Wander • Occasional Forces • Behaviours that produce forces occasionally • e.g. Separation, Avoid Walls, Avoid Obstacle

  41. Ordering Behaviours • Often, behaviours should be ordered in importance. • The ordering used in DK2 was: 1. Vehicles MUST NOT intersect walls. 2. Vehicles SHOULD NOT intersect obstacles. 3. Vehicles should TRY NOT to intersect each other. • How to code this as an expression?

  42. Weighted Average • Take the force vectors from N behaviours, scale them and sum the result. void Vehicle::next_step(){ Vector2d steering(0,0); BehaviourList::iterator i; for(i = behaviour_list.begin(); i != behaviour_list.end(); ++i) { steering += i->calculate_force(*this) * i->behaviour_scale; } …}

  43. Weighted Average Problems • It’s expensive. • Calculate every behaviour for every vehicle each iteration. • When to truncate to max_speed? • Truncation needed to allow important forces to swamp unimportant ones. • Scaling forces leads to undesirable effects. • Scaling path motion forces forces means vehicles movea long paths more slowly than you thought. • How big should the scaling be? • Do scale factors sum to 1.0? • How big does a force need to be to swamp all other forces? • Trial and Error.

  44. Prioritised Dithering • Generate a random value X. • If X < some threshold, execute the first behaviour. • Else execute one of the remaining behaviours until a non-zero force is returned.

  45. Prioritised Dithering void Vehicle::calc_steering() { Vector2d steering(0,0); if(random() < 0.65f) steering = containment(this); if(steering.is_zero()) steering = avoid_obstacle(this); if(steering.is_zero()) steering = follow_path(this); … }

  46. Prioritised Dithering Problems • Continuous Behaviours MUST be randomised. • If they’re not randomised, they will block lower behaviours by always returning a value. • How to design the ordering is unclear. • Which behaviours need to be executed first? • What thresholds are needed to ensure they get priority? • Trial and error.

  47. Gotchas

  48. Path Finding doesn’t take extent into account Paths intersect corners and along the edges of walls. Behaviours had to be robust enough to handle these cases. Extent Problems

  49. Density of objects on the map was often unrealistic. Large creatures couldn’t fit between large obstacles but still had to move realistically. Careful attention paid to cancelling out and truncating forces correctly. Extent Problems

More Related