Presentation is loading. Please wait.

Presentation is loading. Please wait.

UFCEKU-20-3Web Games Programming Game Physics for Collisions and Reactions.

Similar presentations


Presentation on theme: "UFCEKU-20-3Web Games Programming Game Physics for Collisions and Reactions."— Presentation transcript:

1 UFCEKU-20-3Web Games Programming Game Physics for Collisions and Reactions

2 UFCEKU-20-3Web Games Programming Agenda Revise some basic physics concepts Apply concepts to game elements Collision detection techniques Programming collision reactions Game programming world boundaries

3 UFCEKU-20-3Web Games Programming Physics - Some Basic Concepts Physics of Movement Speed Acceleration Velocity Momentum Friction Inertia Physics of Collisions Elastic Collisions - energy of colliding objects is conserved Inelastic Collisions - energy of colliding objects is converted

4 UFCEKU-20-3Web Games Programming Physics -Vocabulary Lengthmetre (m) Masskilogram (kg) Timesec (s) Force mass x accelerationnewton (N) Arealength x lengthm 2 Volume length x length x lengthm 3 Density mass per unit volumep (Rho)kg / m 3 Pressure force per unit areapascal (Pa) N / m 2 Gravity (g) determined by mass of planet9.81 (Earth) Energyforce x distance (in metres)joule (J) Nm QuantitySI Unit

5 UFCEKU-20-3Web Games Programming Physics of Motion Speed = distance traveled / time taken Velocity vector quantity has magnitude and direction Acceleration = change in velocity per unit time Acceleration under gravity g = 9.81ms -2

6 UFCEKU-20-3Web Games Programming Velocity A vector quantity has magnitude and direction Speed = 40 kph East North

7 UFCEKU-20-3Web Games Programming Velocity Resolving Forces Buoyant force gravitational force wind force +y +x

8 UFCEKU-20-3Web Games Programming Force = Mass x Acceleration f = ma Mass Acceleration

9 UFCEKU-20-3Web Games Programming Motion Under Gravity All Objects Fall at the Same Rate...

10 UFCEKU-20-3Web Games Programming Game Physics - ‘Good Enough’ Game physics need only be believable (virtual) Implementing real-world physics may be too resource intensive and visually unnecessary Main visual physics effects Speed - good frame-rate (30 FPS in Flash) Acceleration and deceleration of objects Collisions between objects Trajectories

11 UFCEKU-20-3Web Games Programming Collision Detection Detect when an on-screen game element has made contact with another on-screen game element Collision with game world boundaries Player sprite collides with target enemy sprite Player sprite acquires an in-game resource Collisions must be accurately detected Collision events must be handled by game logic Game state changed to reflect changes made by collisions - update score, lives, acquire energy, add time bonus, more ammo etc.

12 UFCEKU-20-3Web Games Programming Collision Detection for 3D 3D game scenarios may use bounding spheres A bounding sphere is a hypothetical sphere that completely encompasses an object. It is defined by a 3D coordinate representing the center of the sphere, and a scalar radius that defines the maximum distance from the center of the sphere to any point in the object Most game APIs provide some functional collision detection

13 UFCEKU-20-3Web Games Programming Collision Detection in Flash hitTestObject hitTestPoint Code your own function to find the distance between two points ( Pythagoras)

14 UFCEKU-20-3Web Games Programming Sprite Collisions

15 UFCEKU-20-3Web Games Programming Sprite Bounding Boxes

16 UFCEKU-20-3Web Games Programming False Collisions Sprite boundaries overlap but sprites not colliding

17 UFCEKU-20-3Web Games Programming Invisible Collisions

18 UFCEKU-20-3Web Games Programming Invisible Collisions

19 UFCEKU-20-3Web Games Programming Collision Reactions x y -x after collision

20 UFCEKU-20-3Web Games Programming More Complex Reactions x y

21 UFCEKU-20-3Web Games Programming Game World Boundaries 600 800 Game World Area Closed

22 UFCEKU-20-3Web Games Programming Game World Boundaries 600 800 Game World Area Wrapped

23 UFCEKU-20-3Web Games Programming Game Logic: Wrapped World if the sprite reaches the maximum width of the game world then reposition the sprite at the beginning of the game world // assume game world is 800 x 600 if (sprite.x > 800){ sprite.x = 0 } if (sprite.y > 400){ sprite.y = 0 }

24 UFCEKU-20-3Web Games Programming Game World Boundaries 600 800 Game World Area Closed

25 UFCEKU-20-3Web Games Programming Game Logic: Closed World if the sprite reaches the maximum width of the game world then reposition the sprite at the beginning of the game world // assume game world is 800 x 600 if (sprite.x > 800){ sprite.x = 800 } if (sprite.y > 400){ sprite.y = 400 } // would need to take account of the registration point of the sprite

26 UFCEKU-20-3Web Games Programming Game Logic: Closed World Assume registration point at top left corner 100 80 // assume game world is 800 x 600 if (sprite.x > 800){ sprite.x = 700 } if (sprite.y > 400){ sprite.y = 320

27 UFCEKU-20-3Web Games Programming Extended Game World Viewport Game world scrolls to reveal extended boundaries

28 UFCEKU-20-3Web Games Programming Further Reading See the tutorial and investigate the methods of the DisplayObject class hitTestObject hitTestPoint Pythagoras Also the hitTest method of the BitmapData class Game Design Demystified book- good coverage ActionScript 3.0 University - good examples Any of the books by Andre Lamothe Stahler W. et al Beginning Math and Physics for Game Programmers www.gamedev.net - some good articles


Download ppt "UFCEKU-20-3Web Games Programming Game Physics for Collisions and Reactions."

Similar presentations


Ads by Google