Game Physics - Introducing Gravitation & Rotation in Unity
4.5 (855 ratings)
20,463 students enrolled

# Game Physics - Introducing Gravitation & Rotation in Unity

Step-by-step tutorial on how to create a basic rigid body motion physics from scratch. Taught in C# using Unity 3D free.
4.5 (855 ratings)
20,463 students enrolled
Created by Ben Tristem
Last updated 1/2019
English
English
Current price: \$12.99 Original price: \$19.99 Discount: 35% off
16 hours left at this price!
30-Day Money-Back Guarantee
This course includes
• 5 hours on-demand video
• 4 articles
• Access on mobile and TV
• Certificate of Completion
Training 5 or more people?

What you'll learn
• Translate new laws of physics to code.

• ### Extend the capabilities of Unity 3Ds physics engine.

• Transfer this knowledge to other game engines.
Course content
Expand all 45 lectures 05:41:18
+ Introduction & Setup
5 lectures 13:02
Preview 01:25

IN THIS VIDEO...

What you'll need to start

• A Mac or PC that can run Unity 3D or similar.
• You can use another game engine if you like.
• Some coding experience (see sample code).
• Some understanding of mechanics & units.
• Confidence in basic algebra.

Preview 03:10

IN THIS VIDEO...

• An overview of the interface
• How to search for things
• Summary
Welcome To The Course
01:48

IN THIS VIDEO...

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Installing Unity 3D
02:54
Section Summary
03:45
Section End QUIZ
5 questions
+ Newtons Laws of Motion
18 lectures 02:46:52

In this section we will be dealing with a rigid body, and the effect of forces on it.

1. Unbalanced forces lead to accelerations.
2. Accelerations lead to a change in velocity.
3. Velocity determines the change in position.

We will be working backwards through this list, starting with position and eventually creating components to model the effect of various forces on our game object.

Introduction To Section 2
01:26
Section 2 Assets
00:03
Section Notes PDF
13 pages

IN THIS VIDEO…

• Introducing Sir Isaac Newton
• Newton's First Law
• Updating transform.position

• Using FixedUpdate() - Execution Order of Event Functions

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Preview 12:40

IN THIS VIDEO...

Create A Force List

• using System.Collections.Generic;
• Create a public list of forces, forceVectorList;
• Create AddForces () so sum the forces.
• Debug.LogError () if we have a net force.
• Otherwise continue to update the position.
Summing The Forces
11:13

IN THIS VIDEO...

• 2nd Law Defined
• Write Code For Acceleration
• Publicly expose float mass
• Create UpdateVelocity () method
• Modify velocityVector every FixedUpdate
• Remove Debug.LogError() code
Newton's 2nd Law
08:48

IN THIS VIDEO...

• Defining Newton's Third Law.
• Examples of why it's important to consider.
• Introducing our trail drawing code.
• Switching trail direction.
• Recap of Newton's laws
Newton's 3rd Law
08:32

IN THIS VIDEO...

• What we're trying to achieve.
• Why it's important to get this “right”.
• Re-orgainse list iteration for variable forces.
• Bring DrawTrails.cs into PhysicsEngine.cs.
• Move the forces into separate components.
Physics Engine Architecture
15:36
Mid Section QUIZ
5 questions
00:11

IN THIS VIDEO...

• Why it's worth thinking about them.
• Where to annotate our units.
• Prepare our RocketEngine.cs class.

• SI base unit - Wikipedia, the free encyclopedia

(NOTE YOU CAN CLICK THESE LINKS BELOW)

SI Units & Dimensions
10:52

IN THIS VIDEO...

• The thrust of a rocket engine.
• Modelling rocket engines and fuel burn.
• An introduction to “delta V”.

• Rocket engine - Wikipedia, the free encyclopedia

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Rocket Science 101
16:41

IN THIS VIDEO...

• Review the universal gravitation equation*
• Create a method for it in Unity.
• Check we get realistic force values.

• Gravitational constant

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Modelling Gravity
16:01

IN THIS VIDEO...

• Setup a football field “on Earth”.
• Test gravitation matches real values.
• Explore parabolic flight.
• Set scene for air resistance.
Back Down To Earth
12:48

IN THIS VIDEO...

• Design a simple formula for air resistance.
• Create an Air Drag component.
• Test flight against reference ball.
• Tweak to get similar results to Unity's engine.

• Drag (physics)

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Air Resistance
13:09

IN THIS VIDEO...

• Expand on Unity's script execution order*
• Demonstrate our bug at “high” speeds.
• Show how this relates to fixed update time.
• Move Universal Gravity to separate object.

• Execution Order of Event Functions

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Script Execution Order
10:33

IN THIS VIDEO...

• Make a simple hit-the-target game.
• Add a cylinder to represent a rocket launcher.
• Write Launcher.cs class.
Making A Simple Game
19:51

IN THIS VIDEO...

• Re-introduce Universal Gravitation.
• Review the overall structure of what we've done.
Finishing & Tidying Up
05:44

WHAT YOU'VE LEARNT...

• Basic physics engine architecture / trade-offs.
• A foundation in Newton's Laws of Motion.
• Dimensional checking as a tool.
• How to distill information from Wikipedia etc.
• How to create components for various forces.
Section 2 Wrap-Up
02:43
Section End QUIZ
6 questions
+ Simple Rotation
12 lectures 01:26:58
Introduction To Section 3
01:57
• Section Assets Pack
• Previous section project, for Magnus Effect
Section 3 Assets
00:04
Section Notes
8 pages
• The limitations of spinning objects in Unity 5.
• Why unstable rotation doesn't evolve.
• How to model unstable rotation in game physics.
Unstable Rotation In Unity 5
08:37
• Roughly what is an inertia tensor (I)?
• Unstable intermediate axis
• How Unity Calculates I
• Calculate I for your phone
• Predict it's unstable axis
Introducing Inertia Tensors
13:39
• How about if two axis are equal?
• Try it with a spinning cylinder.
• Calculate the moment of inertia.
• Render vs. collider mesh influence.
Calculating Moment Of Inertia
11:35
• NOT the same as Intermediate Axis Theorem.
• How to calculate I for compound objects.
• Think of a discus thrower.

http://en.wikipedia.org/wiki/Parallel_axis_theorem

Parallel Axis Theorem
10:19
• A recap of Newton's laws of motion.
• How these relation to rotation.
• Important differences.
• Why we're jumping in the deep end!
“Newton’s Laws Of Rotation”
08:45
• How to use Unity's AddTorque() method.
• How Inertia Tensor affects rotation.
• Comparing the rotation of two objects.
Applying Torque To Rigidbodies
11:02
• What a cross product is.
• Why they are so useful.
• Using WolframAlpha to calculate.
Vector Cross Products
07:13
• What the Magnus Effect is.
• How we can approximate ball flight with it.
• Using Vector3.Cross in Unity.

The code you need is below...

public float magnusConstant = 1f;

private Rigidbody rigidBody;

void Start () {
rigidBody = GetComponent<Rigidbody> ();
}

// Update is called once per frame
void Update () {
rigidBody.AddForce (magnusConstant * Vector3.Cross (rigidBody.angularVelocity, rigidBody.velocity));
}

The Magnus Effect
11:10
Section 3 Wrap-Up
02:37
+ Making Contact
10 lectures 46:25
Introduction To Section 4
02:40
00:04
7 pages
• Why friction is so important.
• About physics materials and friction.
• How static and dynamic friction relate.
• Using the Friction Direction 2 setting.
• Limitations of Unity's friction, and to improve it.
An Overview Of Friction
08:25
• Welcome “Mu-s”, the coefficient of static friction.
• What the static friction coefficient means.
• How this coefficient relates to slope angle.
• Two triangle trigonometry take-home tricks.
• Testing critical angle in Unity Editor.
Static Friction & Critical Angle
10:35
• Discover slipping angle.
• Try three different static friction coefficients.
• About rolling, and “impulsing” the block.
• Generally horsing around with blocks and slopes.
Make A Friction Test Rig
08:55
• Why we care about friction combine.
• The limitations of Unity's model.
• How friction combine precedence works.
Friction Combine In Unity
03:46
• What is dynamic friction.
• How it relates to terminal velocity on a slope.
• A look at some Stribeck curves.
05:32
• What the Friction Direction 2 setting does.
• How it might be useful.
• A note on using unit vectors.
• Friction Direction 2 doesn't work in Unity 5!
How Friction Direction 2 Works
03:43

Congratulations and how to continue your learning.

Wrap-up & Next Steps
02:45
Requirements
• You need to be comfortable with Unity 3D
• You need to be comfortable with C# scripting.
• You should be able solve basic algebra equations.
Description

Learn to build your own game physics engine. By the end of this mini-course course you will have gained confidence in translating theories of physics into working game code.

I will be teaching using Unity 3D free as the example game engine. I expect you to have some experience with both Unity 3D, and C# before starting this course. If you don't then check out my Complete Unity Developer course.

Why would you take this course?

1. To understand game physics better.
2. Practice creating your own physics components.
3. Improve your knowledge of Newtons Laws of Motion.

Note: We are no longer actively supporting this course, however if we do revisit this subject in the future then students on this course will get the updated content.

Access to this course does come with an optional, free community site where you can share games and 3D models, as well as connect with other students.

See you in there!

Who this course is for:
• This course is ideal for you if you're running into the limits of your game engine's physics.
• If you are not confident in how your game engine's physics works "under the hood", this course will give you that insight.
• This course is probably not for you if you're a physics PhD, who is already confident in coding!