Presentation is loading. Please wait.

Presentation is loading. Please wait.

Collision Response Jim Van Verth

Similar presentations


Presentation on theme: "Collision Response Jim Van Verth"— Presentation transcript:

1 Collision Response Jim Van Verth

2 Essential Math for Games Collision Response Physical response to collision Two main cases Colliding (opposing velocities) Bouncing Resting (orthogonal velocities) Rolling, sliding

3 Essential Math for Games Contact Point Need location of point of collision and normal to surface at actual time of collision We might not have this Objects could be interpenetrating

4 Essential Math for Games Determine Collision Time Do binary search Back off simulation half of previous time step Still penetrating? Back off ¼ time step No collision? Move forward ¼ time step Continue until time step too small or exact collision found Slow, may not find exact point

5 Essential Math for Games Determining Collision Time Or just fake it Determine penetration distance Push objects away until they just touch Can use mass, velocities to adjust how much each moves (ifn you feel fancy) Problem: can cause a new collision this way

6 Essential Math for Games Determining Collision Time Alternative: push apart a little, use collision response to do the rest Assumes collision response can handle penetration Apply force (penalty force) to push them apart

7 Essential Math for Games Determining Collision Time Or use predictive method to determine time of impact (TOI) Integrate up to TOI Do collision response Find next TOI, integrate, respond, repeat until done

8 Essential Math for Games Determining Collision Time Ex: spheres Spheres sweep out capsules, intersect?

9 Essential Math for Games Determining Collision Time Or: relative velocity Compare sphere vs. capsule Sphere centers P a, P b ; radii r a, r b Relative velocity v = v a - v b SaSa SbSb

10 Essential Math for Games Determining Collision Time Idea: determine point(s) on velocity line distance r a +r b from P b Or: ||P b – (P a +vt)|| = r a +r b Or: (w – vt)(w – vt) – (r a +r b ) 2 = 0; w = P b – P a Quadratic: solve for t SaSa SbSb

11 Essential Math for Games Determining Collision Time Expand (w – vt)(w – vt) – (r a +r b ) 2 = 0 Get (vv)t 2 – 2(vw)t + ww – (r a +r b ) 2 = 0 Use quadratic equation, get

12 Essential Math for Games Determining Collision Time Could be 1 solution Just touching, radical = 0 Could be no solutions Never touch, radical is imaginary Pick solution with smallest t 0, 1

13 Essential Math for Games Have Collision, Will Travel Have normal n (from object A to object B), collision point P, velocities v a, v b Three cases: Separating Relative velocity along normal < 0 Colliding Relative velocity along normal > 0 Resting Relative velocity along normal = 0

14 Essential Math for Games Linear Collision Response Have normal n, collision point p, velocities v 1, v 2 How to respond? Idea: collision is discontinuity in velocity Generate impulse along collision normal – modify velocities How much depends on incoming velocity, masses of objects

15 Essential Math for Games Linear Collision Response Do simple case – two spheres a & b incoming velocities v a, v b collision normal n want to compute impulse magnitude f n vava vbvb

16 Essential Math for Games Linear Collision Response Compute relative velocity v ab n vava vbvb v ab

17 Essential Math for Games Linear Collision Response Compute velocity along normal Use dot product to project onto normal n v ab vnvn

18 Essential Math for Games Linear Collision Response Outgoing velocity dependant on coefficient of restitution = 1: pure elastic collision (superballs) = 0: pure non-elastic collision (clay) or

19 Essential Math for Games Linear Collision Response Also need to conserve momentum or and or

20 Essential Math for Games Linear Collision Response Combining last two slides (with a wave of my hand) gives

21 Essential Math for Games Linear Collision Response Compute final velocities n va-va- vb-vb- vb+vb+ va+va+

22 Essential Math for Games Angular Collision Response Like linear, but include angular velocity Compute velocity at collision point vbvb vava rara rbrb a b

23 Essential Math for Games Angular Collision Response Need to conserve angular momentum and or and or

24 Essential Math for Games Angular Collision Response Final impulse equation (more waving of hands)

25 Essential Math for Games Angular Collision Response Compute new angular momentum remember, sim uses angular momentum Then angular velocity from momentum

26 Essential Math for Games Multiple Colliding Contacts 3-body problem (kinda) Do one at a time, will end up with penetration What to do?

27 Essential Math for Games Multiple Colliding Contacts One solution: Do independently Handle penetration as part of collision resolution Another solution: Generate constraint forces Use relaxation techniques

28 Essential Math for Games Multiple Colliding Contacts Crunchy math solution Build systems of equations where, normal component of rel. vel. before & after a i,j describes how body j affects impulse on body i Get matrix equation:

29 Essential Math for Games Multiple Colliding Contacts Results coupled – want as close as possible If (separating) want close to If (colliding) want close to Represent difference by new vector b If then

30 Essential Math for Games Multiple Colliding Contacts Now want to minimize length of vector Impulses are non-positive so want Also want Quadratic programming problem Can convert to Linear Complementary Problem (LCP) – use Lemkes Algorithm

31 Essential Math for Games Resting Contacts Mirtich & Canny use micro-impulses, simulate molecular micro-collisions Works with current impulse system

32 Essential Math for Games Resting Contacts Impulses work, but can be kind of jittery Forces generate velocity into object Counteract in next frame – but still move a bit One solution: once close to rest, turn off sim g

33 Essential Math for Games Resting Contact Velocity along normal is 0, so look at forces along normal If will push together, counteract with new constraint force C = gn, g < 0 Want acceleration along normal If will eventually push apart, want g = 0 So want: 0, g 0, g = 0

34 Essential Math for Games Resting Contact Can build expression for :

35 Essential Math for Games Resting Contact Expand out, end up with expression like Ag repr. acceleration due to response b repr. acceleration due to other forces Remember, want 0, g 0, g = 0 If b > 0, then g = -b/A, = 0 If b 0, then g = 0, = b

36 Essential Math for Games Resting Contact Simple example: assume object on ground, only linear forces If b > 0, then Counteracts force along normal If b 0, then C = 0

37 Essential Math for Games Resting Contact Things get a lot more complicated if both move, and angular terms See Eberly for the full details

38 Essential Math for Games Multiple Resting Contacts Can have stacks of stuff What to do then?

39 Essential Math for Games Multiple Resting Contacts Build systems of equations where Get matrix equation where,, A is the same as with colliding contacts! Another LCP problem – use Lemkes

40 Essential Math for Games Resting Contacts Resting contact is a hard problem Very susceptible to floating point error, jittering Dont do more than application needs Dont get discouraged

41 Essential Math for Games Contact Friction Generate force opposed to velocity For contact: tangential relative velocity Magnitude is relative to normal force If using impulses, can ignore normal force, use constant

42 Essential Math for Games Putting It Together 1.Compute forces, torques on objects 2.Determine collisions 3.Adjust velocities, forces, torques based on collision 4.Predict future collision 5.Step ahead to future collision (if any) or fixed step (if not)

43 Essential Math for Games Recap Try to keep objects non-penetrating Colliding objects get impulses Resting objects either micro-impulses or constraint forces Multiple contacts hard, but manageable

44 Essential Math for Games References Hecker, Chris, Behind the Screen, Game Developer, Miller Freeman, San Francisco, Dec Jun Lander, Jeff, Graphic Content, Game Developer, Miller Freeman, San Francisco, Jan., Mar., Sep Witkin, Andrew, David Baraff, Michael Kass, SIGGRAPH Course Notes, Physically Based Modelling, SIGGRAPH 2002.

45 Essential Math for Games References Mirtich, Brian and John Canny, Impulse- Based Simulation of Rigid Bodies, Proceedings of 1995 Symposium on Interactive 3D Graphics, April (available online)online Eberly, David H., Game Physics, Morgan Kaufmann, 2004.


Download ppt "Collision Response Jim Van Verth"

Similar presentations


Ads by Google