90 likes | 200 Vues
This guide explores essential physics concepts crucial for game development, particularly for understanding motion, collisions, and forces. We'll discuss basic principles like velocity and gravity, and how they affect objects in a game environment, including rigid bodies like circles and rectangles. Learn how to handle collisions when objects interact, including when they meet walls or paddles in games like Pong. The analysis covers static and kinetic friction, along with advanced techniques for detecting and managing collisions efficiently without significant computational overhead.
E N D
Physics • Simple – Pong • Medium – Rigid bodies • F = ma • Circles, spheres, rectangles for collisions • Complex – Fluids, clothings, explosions, hair
Pong • Velocity is constant • Vx = 0.1 • Vy = 0.1 • Position at time t = Px, Py • Position at time t + 1 • Px(t+1) = Px(t) + Vx • Py(t+1) = Py(t) + Vy
Pong • How do I get motion that is not diagonal? • What happens when I hit a wall? • Vx = -Vx (which wall?) • Vy = -Vy • Vx = -Vx, Vy = -Vy (when you hit a corner) • What happens when I hit a paddle?
Pong - Collisions • If Py < Ymin OR Py > Ymax, I hit a wall • If Px < Xmin OR Px > Xmax, I scored/hit a wall Radius = r Ball center compared to X1 - Cx, Y1 r
F = ma • Gravity: F = G * (M1 * M2)/D^2 • G = gravitational constant, D is distance • On earth, assume mass of earth is LARGE so it does not move. Acceleration due to gravity is a constant = 32 ft/sec^2 or 9.8m/sec^2 • V(t) = V (0) t + ½ g t^2 • Vx = Vx + 0 • Vy = Vy + g → choose g to make it look good. • !
Friction • Friction is a function of velocity and mass • Static Friction > Kinetic Friction • Static: when V = 0 • Kinetic: when V > 0 • V = V – friction, if V > friction, else 0
Collisions (again) • Detect Collision • Determine time of collision (why?) • Determine where objects are when they touch • Determine the collision normal • Determine velocity vectors after collision • Determine changes in rotation (advanced:))
Circles/Spheres • If the distance between 2 objects is less than sum of radii • Avoid using square root • (r1+r2)^2 > ((x1 – x2)^2 + (y1 – y2)^2) • If N objects → O(N^2)
Other objects • Collisions are rare • Most of the time objects are NOT colliding • Create a series of filters so that computationally expensive tests are done rarely • Use a grid and only test objects in cells adjacent (touched by) to you • First use bounding circles/spheres, then test further