Download presentation
Presentation is loading. Please wait.
Published byElinor Turner Modified over 8 years ago
1
References: Wikipedia PHYSICS + VECTORS
2
Why physics? Good for every game developer to know. Physics formulae are often vector-based A good chance to try out math3d! Often thinking "backwards" (from pictures to symbolic algorithms) To show you how math3d is usable in pygame Some cherry-picked topics we'll explore: velocity + acceleration (w/ variable frame-rate) Newton's laws of motion Friction Terminal velocity OVERVIEW
3
Suppose you are moving at 50mph for 3 hours. How far are you from your original position? A: 150 miles 50 * 3 Express this as a graph We're really calculating the area of this rectangle. VELOCITY AND ACCELERATION Speed (mph) Time (hours) 50 3
4
What about (abruptly) changing velocity? VELOCITY AND ACCELERATION, CONT. Speed (mph) Time (hours) 50 3 Q: How far have we travelled after these 5 hours? Q (rephrased): In other words, what is the area of the pink area? A: 0.5*(50x1) + (50x3) + 0.5*(50x1) = 200 miles
5
Two options for handling it: Option1: Cap frame rates When moving / rotating express in units / update Bad: Slow machines can't reach the frame-rate Bad: *Very* painful to modify our fps-cap. Option2: Let computer run as fast as possible When moving / rotating express in units / second The multiply by the time since the last frame Good: Runs on any speed machine Bad: Have an extra multiplication VARIABLE FRAME RATES (REVIEW)
6
we can approximate the area of this curve using (small) discreet time intervals VELOCITY AND ACCELERATION, CONT. Speed (mph) Time (hours) 50 3 A dT value for one iteration of the game loop. import pygame # … clock = pygame.time.Clock() #... (inside the game loop) dT = clock.tick() / 1000.0
7
VELOCITY AND ACCELERATION, CONT.
8
VELOCITY AND ACCELERATION change in position due to velocity
9
ACCELERATION
10
ACCELERATION AND VECTORS, CONT.
11
Gravity produces an acceleration on objects Assuming we're on the earth, it points downwards GRAVITY
12
In real life, there's a maximum speed objects can go Theoretically the speed of light. On earth, there's wind resistance. In games, we often impose a terminal velocity More numerically stable. More consistent gameplay experience. A little more like real life. [Develop the formula] TERMINAL VELOCITY
13
NEWTON'S LAWS OF MOTION
14
Gravity is a force Proportional to the mass But…when we apply the force We divide by the mass (Newton's 2 nd ) So…the acceleration is the same regardless of mass Unless there is air resistance (drag) Proved by Gallileo around 1586. In code: 1.Create a Force vector, F 2.Multiply F by mass. 3.Divide F by mass when applying the force 4.Apply acceleration to velocity as normal (or just skip steps 2 & 3) GRAVITY AS A FORCE
15
Friction causes an object to slow down Air resistance Contact with ground …… Implemented as an accleration in the opposite direction of movement Complication: "flipping direction" Complication: magnitude (and connection to dt) [Come up with formula on board] FRICTION
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.