references: http:// flocking
TRANSCRIPT
![Page 1: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/1.jpg)
R E F E R E N C E S :• H TT P : / / W W W. R E D 3 D . C O M / C W R / BO I D S/
FLOCKING
![Page 2: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/2.jpg)
WHAT IS IT?
• A way to simulate "herds":• Flock of birds• Flock of fish• Herd of wildebeest• A group of enemies
First image: http://www.hanskellner.com/2007/03/02/dusk-flock-of-birds-video/Second image: http://www.environment.ucla.edu/podcasts/article.asp?parentid=4002Third image: http://virtualiansanity.blogspot.com/2010/09/lion-king-favorite-scenes.htmlFourth image: http://en.wikipedia.org/wiki/Resident_Evil_4
![Page 3: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/3.jpg)
BOID REPRESENTATION• A generic term for a flocking character• Position ()• 2D: a 2-vector (x, y)• 3D: a 3-vector (x, y, z)
• Orientation• 2D: an angle (0=right, 90=up, etc)• 3D:
• an angle (if your character is always generally upright)• quaternion• rotation matrix• Euler angles• …
• Linear Velocity: the speed the object is moving ()• 2D: a 2-vector (Δx, Δy); Usually in units/s• 3D: a 3-vector (Δx, Δy, Δz); Usually in units/s
• Rotational Velocity: the speed the object is rotating• Only needed if you have independent steering.• A rotation amount per second.• Rotation matrices are hard to use here.• Quaternions are especially nice for this.
![Page 4: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/4.jpg)
BOID REPRESENTATION, CONT.• Independent Steering?• For most characters, the orientation
should match the direction of the linear velocity• Need a refresher on the math?
• Sometimes, you do want a separate facing direction…
• [optional] Max Speed (a scalar)• Useful to keep speed under control• Refresher (with vectors)?
Image: http://www.atariage.com/screenshot_page.html?SoftwareLabelID=906
![Page 5: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/5.jpg)
STEERING
• Adjustments to current position / orientation• Two parts:• Linear (a force, )• • Update the position / velocity like this:
• (this is Newton-Euler-1 Integration; Other approaches include Runga-Kutta-4 integration, Verlet integration, …)
• Note: Unless Δt is infinitely small (which it isn't), the new position won't be exactly where it would be in real life.
![Page 6: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/6.jpg)
STEERING, CONT.
• Rotational (a torque, T)• Only needed if you have independent steering• In 2D
• Recall:• θ = orientation (an angle)• δ = rotational velocity (angles / s)• T = rotational acceleration (angles / s2)
![Page 7: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/7.jpg)
STEERING, CONT.
• Rotational (a torque, T)• In 3D (I'm using quaternions for orientation, etc)
• Recall:• Q = orientation (a quaternion) = [w, ]• δ = rotational velocity (a quaternion, rotation is in angles/s)• T = rotational acceleration (a quaternion, rotation is in angles /
s2)
• Note, to "combine" two quaternions you multiply (like you do with matrices), not add.
![Page 8: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/8.jpg)
FLOCKING OVERVIEW
• Every frame:• Generate 0 or more steerings (force vectors)• From a set of low-level behaviors
• Seek• Flee• Wander• Avoid-another-boid• Align• Obstacle-avoid
• Each force vector is created considering only that behavior
• Combine these steerings into a single force vector• Apply it using the position-/velocity-update formula.
![Page 9: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/9.jpg)
LOW-LEVEL BEHAVIOR: SEEK
max_accel
![Page 10: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/10.jpg)
LOW-LEVEL BEHAVIOR: FLEE
max_accel
![Page 11: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/11.jpg)
LOW-LEVEL BEHAVIOR: WANDER• Approach #1:• Add random.uniform(-m, m) to heading.• Generate a force vector in this direction• Problem: tends to be "jittery"
• Approach #2: • Every few seconds generate a new seek
target.• Problem: can be abrupt.
• Approach #3:• Place a target n units in the heading direction• Add random.uniform(-m,m) to it's rotation• This is relative to the heading direction
• Seek towards this target• Usually a little less "jittery"• Even though the target itself is "jittery"
![Page 12: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/12.jpg)
LOW-LEVEL BEHAVIOR: AVOID-ANOTHER-BOID
• Simple:• If within n units, flee
• More advanced:• Predict if we'll collide, and if so steer to avoid• "Problem" cases:• Moving parallel to each other -- no collision!• Intersecting paths, but no hit.
• Calculating the correction force vector.• Can also consider a "cone of vision"
![Page 13: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/13.jpg)
LOW-LEVEL BEHAVIOR: ALIGN• Given: a direction vector.• Simple -- just accelerate in this direction!
![Page 14: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/14.jpg)
LOW-LEVEL BEHAVIOR: OBSTACLE AVOID
• One approach:
Usually you want to modulate the force based on distance.
![Page 15: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/15.jpg)
BLENDING
• Often, you have more than 1 steering force:• E.g. We want to take a meandering path towards a
target:• Wander ~ 50%• Seek ~50%
• Linear Blending
• w1 + w2 + … + wn should equal 1.0• Why?
![Page 16: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/16.jpg)
BLENDING, CONT.
• Problems:• Contradictory forces (Equlibria)• Oscillating:• If you gradually adjust weights, this shouldn't happen.
• Near-sightedness • E.g. taking the wrong route in a maze.• Combine this with A* to get around this.
• Behaviors that should take precedence:• E.g. Wall-avoid if we're close; otherwise, 0.5 wander, 0.5
seek.• Use a decision tree.
![Page 17: REFERENCES: HTTP:// FLOCKING](https://reader035.vdocuments.mx/reader035/viewer/2022062222/5697bfdd1a28abf838cb15fe/html5/thumbnails/17.jpg)
ADVANCED TOPICS
• Unit Coordination• Formation (echelon, disc, etc.)• Only using cone-of-vision
• Incorporation with A*