Download presentation
Presentation is loading. Please wait.
Published byAron Pope Modified over 9 years ago
1
Calculations in Physics and Game Engines Games Fundamentals © by Jarek Francik Kingston University, London 2007 - 2013
3
Simple Stuff Uniform Motion (constant speed or average speed) If my average speed is 60mph, how long does it take to Bristol (120 miles)? The answer is: v – velocity or speed x – distance or displacement t – time Bristol 120mi
4
Simple Stuff Uniform Motion (constant speed or average speed) Rocket is travelling in straight line from the Earth to the Moon (roughly 360,000 km). How long does it take if its average speed is 10 km/s? v – velocity or speed x – distance or displacement t – time The answer is:
5
Not so trivial, but still simple Accelerated Motion (uniformly increasing speed) v – increase of velocity a – acceleration v 0 – initial speed Rocket is taking off and gaining the speed with the acceleration of a=10 m/s 2. How long does it take to achieve its maximum speed of 10 km/s?
6
Not so trivial, but still simple Accelerated Motion (uniformly increasing speed) v – increase of velocity a – acceleration Rocket is taking off and gaining the speed with the acceleration of a=10 m/s 2. How long does it take to achieve its maximum speed of 10 km/s?
7
Not so trivial, but still simple Accelerated Motion (uniformly increasing speed) v – increase of velocity a – acceleration A new model of the rocket accelerates at a=10 m/s 2 to the mid-point between the Earth and Moon (180,000 km away). What is the maximum speed now?
8
Not so trivial, but still simple Accelerated Motion (uniformly increasing speed) v – increase of velocity a – acceleration A new model of the rocket accelerates at a=10 m/s 2 to the mid-point between the Earth and Moon (180,000 km away). What is the maximum speed now?
9
Facts Apollo 11 top speed was 11.08 km/s (39,897 kmh or 24,791 mph) Average Earth – Moon distance is 384,400 km (238,850 miles) We took 360,000 to simplify the calculations Realistic trajectory of a lunar flight is far from the straight line
10
Facts Apollo 11 top speed was 11.08 km/s (39,897 kmh or 24,791 mph) Average Earth – Moon distance is 384,400 km (238,850 miles) We took 360,000 to simplify the calculations Realistic trajectory of a lunar flight is far from the straight line
11
Game Physics Exercise
12
"Minecraft" is a trademark of Notch Development AB In a physically realistic mod for a game similar to Minecraft there is a small cart of mass 10 kg, standing still in a distance of 6 meters from a solid, vertical wall. Suddenly, the cart acquires an impulse (a hit) J = 40 Ns perpendicularly towards the wall. It moves forward, bounces from the wall and then moves back. How far from the wall is it when it eventually stops due to friction forces? the friction coefficient f = 0.1 coefficient of restitution e = 0.5 gravitational acceleration in this world is similar to the Earth: g = 10 m/s 2.
13
Initially, the cart was standing still, so v 0 is velocity just after the hit: solve in regard to t to find the bounce time deceleration due to friction at the bounce time:
14
Initially, the cart was standing still, so v 0 is velocity just after the hit: deceleration due to friction at the bounce time: after the bounce! time until the stand still: distance travelled: But wait a moment, all that may be done in a much simpler way!
15
Initially, the cart was standing still, so v 0 is velocity just after the hit: deceleration due to friction at the bounce time: after the bounce! time until the stand still: distance travelled: But wait a moment, all that may be done in a much simpler way! solve in regard to t to find the bounce time
16
Initially, the cart was standing still, so v 0 is velocity just after the hit: You may be familiar with the following formula: from which you find the velocity immediately: and further as previously...
17
Initially, the cart was standing still, so v 0 is velocity just after the hit: You may be familiar with the following formula: from which you find the velocity immediately: and further as previously... but this is not yet exactly what I mean...
18
Initially, the cart was standing still, so v 0 is velocity just after the hit: t [s] v [m/s] 0 1 1 2 3 4 2345
19
back now to... the rocket flying to the Moon but this time THE HARDCORE WAY
20
Hardcore Stuff The rocket is now burning its fuel, and the further it’s flying, the lighter it is. Initial mass is m 0 = 20,000 kg and the acceleration a 0 = 5 m/s 2, but the rocket is losing =1 kg/s during the flight. The jet force is constant. What will be the speed and distance from the Earth after the first hour of the flight? Firstly, the easy thing: the jet force can be found from the initial conditions: Now, the mass of the rocket as the function of time: Next step, the acceleration: The acceleration is changing over the time, and the velocity calculation won’t be easy!
21
Physics of Motion Average acceleration is change of velocity over time: Exact acceleration – is the derivative of velocity: To calculate velocity (as a function of time), you simply need to integrate velocity in regard to time:
22
Physics of Motion To calculate velocity (as a function of time), you simply need to integrate velocity in regard to time: – if acceleration is constant: – if acceleration changes over time – integrate!
23
Physics of Motion Average velocity is displacement in time: Exact velocity – is the derivative of displacement: To calculate displacement, you need to integrate velocity in regard to time:
24
Physics of Motion To calculate displacement, you need to integrate velocity in regard to time: – for Uniform Motion: – for Accelerated Motion: – for any other type of motion – simply integrate!
25
Hardcore Stuff After an hour of flight (3600 secs): Knowing acceleration, calculate velocity:
26
Hardcore Stuff After an hour of flight (3600 secs): Knowing velocity, calculate displacement:
27
Hardcore Stuff Let’s go to the next level of difficulty – the rocket is affected by the Earth gravity. In outer space, this is non-linear and drops with the square of the distance from the Earth – the rocket is also affected by the Moon gravity. It’s non-linear and rises with the square of the distance to the Moon – the jet force is not constant: it is controlled by the astronaut and may change in any time, irregularly
28
Numerical Integration Wait a moment, there must be an easier way: – Game Developers are smart, but they may not like integrating that much – Methods of analytical integration are not even covered in this module! – Logarithms are hard to calculate for computers So? Of course there is!
29
Numerical Integration t [s] v [m/s] approximated value! good if t is small enough
30
Numerical Integration t [s] v [m/s]
31
Numerical Integration t [s] v [m/s] difference equations – equations that determine the difference between the (n) th and the (n+1) th
32
Numerical Integration t [s] v [m/s]
33
Numerical Integration t [s] v [m/s]
34
Numerical Integration double v = rocket.GetSpeed(); double m = rocket.GetMass(); m -= mi; double a = F / m; v += a; rocket.SetSpeed(v); rocket.SetMass(m); rocket.Update(GetTime()); this function updates the sprite’s location t is often considered to be 1
35
Numerical Integration Numerical integration is based on repeating simple operation (addition) many times Numerical Integration is approximate, but with small values of t it is sufficiently good If you have any concerns, play Angry Birds (or any other game with good physics)
36
Numerical Integration Most people are not very good in integration Mathematicians are good in symbolic integration, but computers find it challenging Computers are very good in numerical integration, but people very ineffective in it!
37
Numerical Integration Integrator – any component (hardware or software) calculating a single sample in Numerical Integration GFC OnUpdate / Update functions are examples of integrators CSprite::Update function uses the current velocity to update the position of the sprite moving it by x = v t, and t=1/60 sec. Another example of basic integration step is modelling the gravity: sprite.SetVelocity(sprite.GetXVelocity(), sprite.GetYVelocity() - 10);
38
Numerical Integration Interpolating Functions used in NI: – rectangle rule – trapezoidal rule – Simpson’s rule (parabolic)
39
Today’s Workshop Task In Your Rocket: – throttle is controlled by the player – the more thrust, the more fuel is burnt – the total rocket mass is the net mass plus the fuel – the rocket operates in the overlapping gravitational fields of the Earth and the Moon – the net force acting on the rocket is a sum of the two gravitational forces and the engine thrust – calculate the acceleration from the 2 nd law of motion
40
Isaac Newton’s Law of Universal Gravitation Every point mass in the universe attracts every other point mass with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between them
41
Isaac Newton’s Law of Universal Gravitation Every point mass in the universe attracts every other point mass with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between them r M m
42
Values Gravitational constant G is one of the fundamental constants of our Universe G Gravitational Constant6.67∙10 -11 Nm 2 kg -2 Mass of the Earth5.97∙10 24 kg Mass of the Moon7.35∙10 22 kg (0.0123 Earths) Radius of the Earth6378 km Radius of the Moon1737 km (0.273 Earth) Average Earth-Moon distance384,400 km Average Earth-Sun distance149,597,870 km
43
Values In a Game Engine rarely there is a need to use real world values GM value for the Earth12000 GM value for the Moon3000 (0.25 Earths) Radius of the Earth225 pixels Radius of the Moon180 pixels X coordinate for the Earth-100 X coordinate for the Moon900 Earth-Moon distance1000 pixels own mass of the rocket120 – plus up to 100 fuel thrust multiplier25 these are simply the values that worked fine for me a very much different set of values may be fine for you
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.