The Ultimate Guide for Physics in Game Development!
Video Overview & Insights
In this video, I am going to thoroughly go over everything about physics in game development. Regardless of whether you are a complete beginner and don’t know what a force is, or a seasoned game developer who uses physics all the time, I can almost guarantee that you will take something new away from this video. This is the ultimate guide for physics in game development.
CORRECTIONS:
- gravity on earth’s surface, g, is 9.8 m/s^2 and not -9.8m/s^2. The negative comes from saying that it is “pulling you down” and not “pushing you up”
- a normal force is not just the force that counters gravity. In a Goldilocks scenario where the object is on a flat surface, it is, but normals are perpendicular to the surface, not just straight up in the air.
If you find more leave a comment and I’ll add it here!
The video is broken up into 8 different sections and in each section, I first go over the core concept and then show you how it can actually be used. The sections are kinematics, Forces, Friction, Drag, Collisions, Impulsive Forces, Rotational kinematics and dynamics, and the Rigidbody Component.
In the video, I use the unity game engine (particularly unity 3D), but physics is physics and the concepts and themes will be the same regardless of the game engine you use.
Better than school btw 😩🥹😍
Links:
Project File: https://github.com/WillHess3/Unity-Physics
I don't understand anything 😭
Full Hammer and Feather Video: https://www.youtube.com/watch?v=oYEgdZ3iEKA
Chapters:
woooow
0:00 - Intro
1:18 - Kinematics
It's just a game. Anything can happen.
9:44 - Forces
19:08 - Friction
Stat:( Kinet:(
27:14 - Drag
33:38 - Collisions
Skills gained after completing:
Systems thinking, collision detection edge cases, real debugging reasonings, spatial paritionings, memory management, algorithmic optimization.
40:39 - Impulsive Forces
46:23 - Rotational Motion
I kept thinking throughout the whole ramp demo "what are we breaking exactly?" until I realized he meant "braking"
56:11 - Rigidbody Component
1:02:13 - Recap
My goat
Kinematics is the branch of mechanics concerned with the motion of objects without reference to the forces which cause the motion. This basically means that we are calculating an object's motion from some initial set of conditions and the time elapsed. Here we are not going to consider any forces. In game development, we can incorporate this concept with the kinematic equations. The main kinematic equation and the only one you really need is xf = 0.5at2 + vt + xi. In Unity, we can make a script in C# that has a function with the kinematic equation coded in. This way we can set up some initial conditions and launch objects in our video games.
Kinematics is pretty good, but there are some drawbacks. The biggest one (at least for us game developers) is the fact that handling collisions with kinematics is very difficult because you would have to program it all yourself. It is a much better idea to let the unity game engine handle all of that stuff and you use forces.
Great vid understood every bit great narration, I see last vid was 1 yr ago. Would be great if this vid series continues thanks anyway
A force is a just a mass times an acceleration, and they can be constantly applied to an object to accelerate it realistically. We can use forces in our games this way to simulate things that are constantly getting faster. The demo I used in the video was rockets accelerating forward in space. In Unity we can use forces by calling the AddForce function on our Rigidbody.
Friction is a type of force that resists the motion of two objects in contact and is the force responsible for making objects stop moving when no other force acts on them. The force of friction is equal to the coefficient of friction times the force normal. In unity we set this up by adjusting the two friction values in a physics material. the friction values on the two objects in contact get combined somehow to produce the coefficient of friction used in the actual calculation. If no physics material is on an object it will behave as is it has a static and dynamic friction of .6
Hey Will, this is super impressive! Hit me back up. I’d love to connect about a video game that I need a dev person with this level of physic understanding.
Drag is another resistive force that resists the motion of an object as it is suspended in free fall. The force of drag (simplified version) is equal to -bv. In unity however the drag variable doesn't equal b, it equals b / m or g / vt where vt is terminal velocity.
There are 3 main types of collisions, elastic collisions, where no energy is lost, inelastic collisions, where some energy is lost, and perfectly inelastic collisions, where all energy is lost. No matter what type of collision you are facing, momentum is always conserved. We can determine a collisions elasticity in unity by using the bounciness variable in our physics materials.
Just wanted to point out that, at 10:08, you equate 1kg to be approximately 2.2lbs, but the kilogram is a measurement of mass while the pound is a measurement of force. This equality only stands when under the influence of Earth's surface (or that of any other body of equal surface gravity) and when the measurement of force is referring to that caused by gravity. You do address the difference between mass and weight immediately following this, but you never directly acknowledged the connection between this difference and the equality from before. Besides this--rather pedantic--technicality, excellent video!
Impulsive forces are a way for us to quickly change an objects momentum. We could realistically do this by having a very high force acting over a short time, or we could just do a cheeky game developer move and do it instantly. To do this in unity all you have to do is type ForceMode.Impulse as the second argument in the AddForce function. This is probably one of if not the most important topics in the video.
Rotational motion is broken up into two mini sections with the first being on rotational kinematics. It's exactly the same as regular kinematics except just using the rotational variables. The next mini section is on rotational dynamics mainly just focusing on torques. Torque is the measure of the force that causes an object to spin around an axis. It equals the position vector crossed with the force vector, and also an object's moment of inertia times its angular acceleration.
There is a problem with the first catapult demo, that leads to not resulting in a curve when you launch the rock. You don't update the initial velocity along y every frame, although it gets changed by the acceleration. So you kinda push the velocity up a bit every frame, leading to not a curve but basically a bit wiggly but straight line at the same angle all the time
In the last section I just went over everything else about the Rigidbody component in Unity.
Subscribe: https://www.youtube.com/WillHessGameDev?sub_confirmation=1
Mfs who dont use an game engine 🗿🗿
Instagram: https://www.instagram.com/will_hess_yt
Discord: Will Hess(hashtag)9883
Thanks for taking time to make this amazing tutorial on physics in games. It has been a great help! :)
If you have any questions DM me over Instagram or Discord
One thing I would change is that in the brakes example, I would apply the force opposite to the cars velocity and not just backwards.
It wont really matter if the car moves only forward, but its better and not even harder to code.
More User Perspectives
thanks for this tutorial
@styyle300I wonder what is necessary to find a job as physics programmer. Many tutorials cover more or less what you nicely showed here, but I'm not exactly sure of the next steps that would help one to find a job are
@netolcc064:26 well you kinda do... I mean with small everyday objects you really dont but the gravitational acceleration is generaly found using this formula
F = G * ((m1 * m2) / r^2)
- G => gravitational constant
- m => mass of an object
- r => distance between objects
there are masses of both objects but when one is earth weighting trilions of tons and another 4 kilogram ball, its not gonna do much... the difference is negligable but with large objects you have to account for that
Thank you for this! Amazing video!
@w.mcnamaraDude.. this was awesome and very educational. Great job! Thank you.
@brodgers123No way man, I'm literally seeing this video procrastinating for my exam tomorrow and you just explained drag really well and right after my teacher said there will be a question on drag and terminal velocity
@miguelflorentino745025:50 the friction value of all involved objects is set to 0.58, but it suddenly changes to 0.57 during the next step because of the script. This is jarring and makes it more difficult to understand. Was there a reason you did this that I'm missing?
@HxTrEmEcHaOsWith all respect: How old were you when you made this video? I find it fascinating that someone a fraction of my age can teach me so much. Thank you for this knowledge.
@munchymonk9021leaning tower of pizza lol
@DoctorSpaniel1:01:30 Example use cases for these functions:
GetPointVelocity: You are programming (at least somewhat realistic) car physics, you need to find the individual velocities for each wheel. They may differ significantly, for example when doing a donut, so using the velocity of the Rigidbody is not sufficient. A local-space variant also exists for this called GetRelativePointVelocity.
ClosestPointOnBounds: I could not come up with a use case for this function, but in the video you say "closest point on the rigidbody's collider" which is not actually what this function does, it gives you the closest point on the Axis Aligned Bounding Box of the Rigidbody. If you want the closest point to the Rigidbody you should use...
Collider.ClosestPoint: You are programming a space exploration game, you want to implement a collision warning sound that beeps faster the closer your spaceship is to an asteroid. You can get the distance to the asteroid's surface by calculating the distance between the closest point of the asteroid's collider and the spaceship's position.
Just to those of you who are curious. Speed is the time rate at which an object is moving along a path, while velocity is the rate and direction of an object’s movement. Put another way, speed is a scalar value, while velocity is a vector.
@EdamHamza"brake" not "break" for the car example.
@johnterpack3940All this video needs is simplified definitions of the jargen amd its perfect
@jayjayrin3080Now that im older i realize that subjects taught at school are taught for the sole purpose of teaching, its never said "why" we might need to learn "insert subject here" and the showing of such scenarios, we are just expected to learn and never know why until we figure out the why for ourselves, but by then we need more than a "Refresher"
@jayjayrin3080Ty I'm giving my board exams😅
@SHAFKAT_KHANHave you tried 3blue1brown's manim library? The library is very helpful for presentation😅
@hsjwvsIm less than half way in the vid and its amazing. WIll Hess u did an amazing job. Keep it up! You earned my like!
@ChupapiGringowhast the radians
@bradenwilson680For me the worst thing in physics is dealing with delta time
@filip286515:10 Yes "a" is indeed the correct answer for a force that counters gravity. "b" is the answer for correct normal force. But hey! It's a tricky question, don't feel bad for getting it wrong, and explaining it wrong to how many now 148.681 people xd
No, normal force has nothing to do with gravity itself lmfao
This is truly outstanding, thanks for making this! I'm halfway in, the only thing i would have liked to be explained additionally are the "Force Modes" for the Rigidbody AddForce method, what they mean and what the default Force Mode is and how it operates. I see that later in the video, the Impuse Force Mode is used as well, I just thought perhaps explaining it earlier on gives better context for the Unity examples.
@dreamisover9813need a vide on game math also
@MADARA-UCHIHAGAMINGBro, this video is legendary! Thank you so much! Instant sub
@vitobrxOne of the best videos I’ve seen pure concepts and how to apply I’m very proud of you :)
@iamyou6555Thanks, I’m making a game engine in Vulkan
@5DPixelthanks bro, so clear
@christopherfrancique9912This is a pretty good tutorial, thank you. It’s well detailed. Can you make another version in the future that does everything from scratch (assuming we already have a simple and basic 3D renderer already in place, no game engines)?
@XanCraft21I would need to rewatch this many times. 🫣
@johndouglas6519Brother u made me like physics again
@dragonninja9908best, clearest explanation of this topic I have found yet
@joshparrott438946:50 Don't know what you meant, but radians are not 'a fraction of pi'. Pi itself is in radians, and a radian is a unit of measure.
@ScorgusThis was invaluable to me as I am learning game development. I greatly appreciate this lecture/tutorial! World Class!!!!!
@jermaineallgoodermm sexy video?
@NaKiqua