+ All Categories
Home > Documents > Collision Detection

Collision Detection

Date post: 05-Feb-2016
Category:
Upload: teness
View: 39 times
Download: 0 times
Share this document with a friend
Description:
Collision Detection. Presented by Jerry Ashcroft-Thew. What is collision?. Physics. the meeting of particles or of bodies in which each exerts a force upon the other, causing the exchange of energy or momentum. - PowerPoint PPT Presentation
Popular Tags:
26
Collision Detection Presented by Jerry Ashcroft-Thew
Transcript
Page 1: Collision Detection

Collision DetectionPresented by Jerry Ashcroft-Thew

Page 2: Collision Detection

What is collision?

•Physics. the meeting of particles or of bodies in which each exerts a force upon the other, causing the exchange of energy or momentum.

•Games. When two objects attempt to occupy the same space in the coordinate planes, or world.

Page 3: Collision Detection

When does collision matter?

•Preventing two objects from ghosting through each other

•Prevent an object from simply hovering when it should fall

•Detect projectile contact for “hit” vs “miss”

•When might you NOT want collision, when it would occur in real life?

Page 4: Collision Detection

Components of Collision

•Detecting if a collision occurred •Reacting accordingly

•Discovering if a collision has occurred is the basis of this problem.

Page 5: Collision Detection

Detecting collision

•The first step is to find out if the camera or player will pass through any polygons or planes on its next move

•All polygons are extended indefinitely along their plane. If the camera does not intersect the plane, then no calculations are necessary (less processing). When a collision with the plane is detected, then check if the camera intersects the polygon itself.

Page 6: Collision Detection

2D Collisions

•Much easier to detect•World can be represented by 2D array

grid

Page 7: Collision Detection

Tile Example

•Detecting collisions with tiles•Player occupies one tile, all objects made

up of tile sized pieces•When the player moves, check if the new

tiles it occupies contains any objects we want to collide with instead.

•Update player position accordingly

Page 8: Collision Detection

Collision Detection Mathematics•Vector - directed line segment with

magnitude and direction. i.e. angle and length or distance.

•Vector can also represent force or speed of an object

•A scalar, as opposed to a vector, has magnitude, but not direction.

Page 9: Collision Detection

Vectors

•Different ways to express vectors:▫V = P2 - P1▫V = (x2 - x1, y2 - y1)▫V = (Vx, Vy)

•A 2D world has only x and y components, whereas a 3D world adds the z axis and another component to each vector.

Page 10: Collision Detection

Vectors cont.

•Vectors determine how far apart objects. •The length of the vector can be found by

the distance formula for two points•2D Vector: |V| = sqrt(Vx2 + Vy2)• 3D Vector: |V| = sqrt(Vx2 + Vy2 + Vz2)

Page 11: Collision Detection

Normalizing Vectors

•Off topic, but still important•Divide each component of the vector by

its magnitude.•Creates Unit Vector

•A plane's normal unit vector is important to provide realistic lighting and collision detection.

Page 12: Collision Detection

The discrete time issue:

•What if objects collide between updates?•Imagine the following 2D scene: a black

ball is standing still,•and a white ball moves quickly towards

the black ball•If the white ball can cover more pixels in

one frame than the black ball's diameter, we may not detect the collision

Page 13: Collision Detection

Solution:

•Keep track of distance between relevant objects

•If distance suddenly changes sign, i.e. becomes negative, we have passed through the object

Page 14: Collision Detection

Quick collision detection

•Use Bounding Geometric shapes•If general shapes collide, assume collision

occurred.•Sphere or circle, Cylinder or rectangle•Not very precise…

Page 15: Collision Detection

Sphere-Plane method• Uses the quick collision detection, but with

polygons of the environment• Test if player-sphere intersects the plane of

an objects polygon• The viewer or camera can be thought of as

one solid entity, such as a ball, instead of a creature with several limbs.

Page 16: Collision Detection

Sphere-Plane cont.

•Easier to calculate – all points on the sphere are equidistant from center

•Thus it is easy to determine if an object intersected with the sphere

•If distance to an object is less than or equal to radius, then collision occurred, and we react accordingly

Page 17: Collision Detection

•Main point – don’t get too close!•Use planar equation Ax+By+Cz+D = 0 to

determine normal vector, <A,B,C>•To find distance between sphere and

plane of an objects surface, dot product the normal vector with the position of the sphere, or its center

•Distance = Normal Vector of Plane DOT Position of Center of Sphere

Page 18: Collision Detection

•The distance will be either positive or negative, depending on the side of the plane you are on. – Useful for the discrete time issue mentioned before

•If the distance becomes less than the radius of the sphere, or if the sign of the distance vector to the wall changes, a collision has occurred

Page 19: Collision Detection

Reacting Accordingly

•What are our options?▫Stop altogether▫Slide along surface▫Slow down and push object▫Bounce off object▫Sink into object▫Pass through object and ignore collision

Page 20: Collision Detection

The Sliding Plane

•The plane with which we will continue our movement

•Sliding Plane = Tangent plane to place on sphere which collides with the object

Images taken from http://www.peroxide.dk/papers/collision/collision.pdf

Page 21: Collision Detection

•To find the tangent plane, we need 2 things▫Normal vector▫Point on plane

•Point on plane is point of intersection•Normal vector is simply vector from edge

of sphere (our point of intersection) to center of sphere

•Now we have the tangent plane, and thus the plane to move along after a collision!

Page 22: Collision Detection

Sliding the Sphere

•Move as close to surface as possible•Find sliding plane•Project original velocity onto sliding plane

to get new position•Make new velocity vector by finding

distance from collision point to new position

•Recursively call the entire collision detection routine with the new position and the new velocity vector.

Page 23: Collision Detection

•Recursively call the collision function and check ALL nearby surfaces again.

•Continue until:▫No more collision is detected, or▫Velocity vector is very small

•Run into a corner, don’t want to slide through one wall because it was ignored.

•More directly we hit a wall, the less we slide along its surface!

Page 24: Collision Detection

Gravity

•Very easy once you have a working collision function

•Just call the function twice, once with the velocity vector, and once with the gravity vector

•Allows for climbing stairs and ramps, or falling from heights with automatic acceleration

•NOTE: PAY ATTENTION!

Page 25: Collision Detection

Homework

•When might you NOT want collision in a game, when it would occur in real life?

•What is the limiting factor with combining gravity and velocity vectors into one call of the collision function instead of separating it out?

Page 26: Collision Detection

References

•http://www.peroxide.dk/papers/collision/collision.pdf

•http://www.edenwaith.com/products/pige/tutorials/collision.php

•http://www.dictionary.com•Google image search


Recommended