Found this video per chance while searching for physics engines after giving up on writing my own. Now I'm almost finished writing it. Thanks for the very well-explained overview! Definitely earned a sub from me.
In all seriousness, this is gonna help me a lot, especially the part at 1:15, I've been making a game engine and wanted to fiddle with my own physics but didn't know how I should first mold it, and something basic like that (although translating it into a component) is perfect. Thanks so much.
Hey! I've been working on a rendering + physics engine for about 7 years now, not it takes that long to make it, but I went in and out of it as time passed and life allowed me to work on it. I'm definitely inspired by this video to create my own physics engine. Looking forward to the next video! :-).
I think you should do both. Continue with more videos on design and dive deeper into the math in another set of videos. I wish I had a video like this when I was pulling apart physics engines for the first time. This is a quality overview. Great job.
Thanks! You know what, I think that might just be the way. I could cover some of the algorithms that have few concise explanations. I bet I could make a good GJK video...
@@Winterdev GJK is an advanced and often poorly explained distance algorithm. To be meaningful it also requires an understanding of linear algebra and affine geometry. I'd like to see how you handle it.
I did not know it was possible to show code in a video and keep it understandable, but you did it! Very nice video. I'm a bit more interested in the math of e.g. what happens after a collision, or how to prevent errors in the simulation from building up and sending the spheres flying. But honestly I'll definitely watch the next video in the series, whatever it is!
Thanks! I'll get into that in the next part about physics. I don't have it planned, but when I get to it I'll lean a little bit more into the math. If you want to check out the code for the response, it's here and decently readable: github.com/IainWinter/IwEngine/blob/master/IwEngine/src/physics/Dynamics/ImpulseSolver.cpp
this is an amazing explanation I'm working on my own 'game engine' (more of a library than anything ) and I wanted to make a physic engine as a fun task, and this video explains things so well
Haha thanks, that is my goal, to make the tutorials that I needed. It seems I'm not the only one that wished there was clearer info on these topics! :)
Brilliant video, I would love to see a video on the ECS you mentioned as I'm currently implementing my second iteration of a ECS and am curious to see how accomplish it. Keep up the good work
Thanks, I'll note that to do next after these sand vidz. That's prob not going to be for a while, but if you want to get some ideas the source code is here and not too messy, I think this was also my 2nd or 3rd go at it github.com/IainWinter/IwEngine/tree/master/IwEngine/include/iw/entity
That... explains a lot... A while back, was trying to figure out why all the collision detection stuff was reactive to objects clipping together. Apparently, this is the norm. I wonder if I can make it more proactive. Maybe with a raycast?
When I made a physics engine as a university project I came up with a very similar structure myself. Code was a lot more mess) but the principle of collision solving was the same. The most challenging part btw was an angular motion
Pretty cool overview, at least of the basics. Would be neat to see you integrate your GJK video with this video to create something a bit more realistic and useful than simple sphere vs. plane.
Winterdev: Codes a physics engine in 5 minutes, provides glimpses of classes but doesn't provide the source code Me: Can I see the full source code, so that I can run and experiment with it? Winterdev: NOOOOO, don't you know how much TIME and hard work went into this??? How can you put such high expectations on me???
@@Winterdev Thank you, and sorry for the harsh comment, I just see a lot of bait on YT nowadays, trying to give ppl the false sense they've learned something when they've just made eyecandy for viewers
Hey thanks a lot for your video ! I have two question :p First: For the motion equation when you write [x=vt+x0] with [v=F/m*t + v0] I didn't get why when you integrate the velocity you don't have the 1/2 for the position. because x should be equal to [x=F/m*t²/2+v0*t+x0] so you can't write [x=v*t+x0] or am I stupid ^^ Second: What do you use do make your formula and code animation ? :)
This was talked about quite a bit over on the hn page here news.ycombinator.com/item?id=24016718#up_24018883. It's a pretty interesting read. I've been using HTML and CSS for these 😂
Thanks! Yes, I think I am going to throw that in with angular stuff when I get back to physics. The code is decently clear if you want to look at it github.com/IainWinter/IwEngine/blob/master/IwEngine/src/physics/Dynamics/ImpulseSolver.cpp
Great video! I’d love to know how all of this polymorphism affects performance. While it has a great design, I’m not sure that it will be performant, lots of dereferencing and dynamic function lookups. I’d think this would have terrible cache coherence.
The performance will be trash for more than the reasons you listed. Consider that every static object will need a collision test between every other static object, which is ridiculous. Which objects collide with which objects is something you need to tightly control (say, should a bullet interact with a gravity volume?) for performance and behavior reasons, and the approach in this video isn't good enough.
@@MisterFanwank Yeah one of my biggest regrets with this design was the double dispatch call. I later found a Valve pdf (page 33) that describes a 2d array of function pointers, then you use a ColliderType enum to index it. This lets you define all the possible collisions in one place and effectively centralizes the virtual function table. You could add another enum and follow this pattern for the object collision masks. The performance worked for my tiny games, but you definitely need a form of broad phase check/data structure for anything larger. valve: pdf media.steampowered.com/apps/valve/2015/DirkGregorius_Contacts.pdf
Thanks for the cool video. Just curious, what are the reasons for writing your own physics engine rather than using open-source engines such as Bullet or Mujoco? Not saying you shouldn't do it, even out of interest, but are there any objective reasons to do it?
It started as a project for a physics class and then I realized I could use it for the simple games I was making. Over time I got invested in it :) I think other than coding exercises you should use a library, but I think it’s important to understand what the computer is doing so it’s def worth it to try and make one yourself.
Great work on explaining this in such a simple way! Would you mind clarifying what you meant by Position Solver and Impulse Solver? I didn't understand this part. Thanks!!
Thanks! They inhreit from 'Solver' and process each CollisionPoints. The idea is that the impluse one solves for the force of each collision, and the position once corrects the position directly for some error correction. You can check out the source of these here github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics/Dynamics
There was but I’ve changed it form what it was for this project. For this all it was an x y z and operator+. In the collisions the dot product is used I think.
Your video is brilliant, it was a great pleasure to finally find someone explaining all that stuff in such a simple to understand format. I do have a stupid question for you, though. Don't get me wrong, but how did you get [ x = x0 + v∆t ] when describing uniformly accelerated motion? I mean, for that to be true, [ ∆x = v∆t ] would have to be true too, but [ ∆x = v0∆t + a∆t^2 / 2 ] (as was shown in the video)? I don't get why we calculate [ obj->Velocity += obj->Force / obj->Mass * dt ] and at the same time [obj->Position += obj->Velocity * dt]. Could you, please, at least briefly explain it in a reply to my comment, please? Thank you very much in advance
Thanks for the comment! Someone in the hacker news discussion was talking about that on similar lines news.ycombinator.com/item?id=24019099. My understanding is if you update the velocity then the position in the code, ∆x = ∆vt and ∆v = at. When you take the derivative you get ∆x = ∆v + a∆t^2 / 2. I think in the code if it were too update the position then the velocity, this would be an issue, but because the velocity gets updated then the position, those equations are equivalent.
@@Winterdev Thanks! Yeah, I guess the key is that we expect ∆t to be so small that we can afford getting some measurement error by calculating ∆x as if the object were moving uniformly without acceleration whatsoever. Also, like you said, this would be an issue if we calculated ∆x first, since then we would not really use acceleration anywhere at all. Thanks for clearing that up!
Great video! But I have a question, how did you do the graphycs of the video? Like the dynamics title and those trancitions. I want to do videos like this, but I don't know how to make them visually apealing
If you’re asking where to make something like this? Anywhere you can see the results! So you could print to console or use unity to easily display, tho that’s in C# not C++
So I’m researching physics engines for racings games and I have a question if everyone can answer it (I haven’t fully watched the vid yet so bear with me) when it comes to making a racing game, for the cars to of course drive and drift. Is that done purely from coding in, the gravity, and friction from the wheels? So that once you brake the physics would cause the wheels to loose friction causing them to drift? I know that the wheels have their own collision, allowing the vehicles to drive. I just have no idea how it makes the car move and the thing that confuses me the most, drifting.
Well it depends on how realistic you want it. I’ve never made a racing game but you could do what you described or you could just have a simple obj following a path like Tube Slider
@@Winterdev I did some digging after leaving that comment and that is a common way to do it apparently when making physics for racing games. By having the wheels separate objects from the body, still attached of course, and giving them physics like friction and then just change them depending on what you want wether it’s a drag, drifter, or off-roader
Thanks, I'm still getting that down, there are written versions as well so I don't really know if I should made fast videos or not... Here is the article if you're interested: blog.winter.dev/2020/designing-a-physics-engine/
...Is collision detection between primitives really as simple as separate functions for each possible interactions between all the different shapes? Is there not a better, more easily extended way to do this?
I noticed in the source of PositionSolver that you're displacing both colliding objects by resolution. Wouldn't it make more sense both objects only by half of it?
If you could, I would love to see a tutorial on implementing these things! The dynamic part was pretty easy but I've been trying the collision for days and it's constant errors and nothings working. I tried using the engine you're developing as a reference but its way ahead of where I'm at xD Im just not sure where to put the classes and stuff, any help is appreciated!
I don't know your specific code, but I'd try and start with something as simple as possible to get an idea for how it should come together/what the issues are. You could start with making a 'Collider' that is just the sphere one because it's the more basic . Then you could store these in a list, really anywhere, and loop over them getting the responses if there is one and moving them by that response. I might make a version of this with impl, but not for a while as I am trying out some other topics besides physics. gl with your code :)
@@Winterdev Thank you!!! Gonna move onto the Mesh Collider stuff next! (GJK and EPA) Would love to see videos going into the math (how to attach it to a custom model and have it work!)
Oh nice good luck!! When you say attaching it to a custom mesh, is that from a visible mesh to a physics one? Or any type of collider attached to whatever game object so they move together.
So I was trying to follow along this, however I quickly ran into the issue of there being no vector3's (or vector 2's) in the std library or anywhere else, where are those coming form ? When trying to create them as a struct I can't do the needed maths with floats later on.
It’s a little unclear but those come from me. All you need for this are structs with 2 or 3 floats for x, y, z and maybe a length / dot product function which are both 1-2 lines so I didn’t cover that. I might add a small gist to the description
@@Winterdev A gist about it would be greatly appreciated, I for now created my own PhysVectors with the required coordinates and operators that should do for now.
Thanks, if you watched my recent dev log I have these asteroids flying around that need the rotational collision response so I’ll make a vid covering colliders when I talk about that in a couple weeks
Does youtube keep deleting my comments? I'll try one more time. Dynamics is more complicated than that. What you described here is the explicit euler method, which is unstable and unusable in physics engine. You might want to check out Erin Catto's 2015 GDC talk where he demonstrated the semi-implicit euler method, which most modern physics engines use.
Someone else was having their comments deleted too, idk why sorry. I watched that video and it looks like that I am using what's called semi-implicit Euler, which Eric concludes is the most common. That makes since to me because it's what you naturally end up with when translating the kinematic equations directly to code without thinking about it. Let me know if I missed something, thanks for the comment :)
Ok so I get the math of the physics engine, but how do you visualize it? I tried setting up OpenGL but now I am hours into getting that to run and take a simple input when i wanted to build a physics engine for fun lol.
Lol I feel your pain. OpenGL is as complex if not way more than the physics engine and impossible to debug if you don’t know where to look. I’d lookup GLFW which wraps all the nonsense (window/input/update loop) up for you, but you still need to pass a mesh by hand and have shaders setup. Maybe look for a renderer library that is made to be as simple as possible
@@Winterdev yeah in using GLFW. I'm a first year undergraduate computer science student. I built a ray Tracer and thought "all this math was cool, I should make a simple little physics engine." I think I'm gonna be able to understand GLFW and the physics but combining them might be problematic, I will figure it out! Or not, I have an internship starting next week so bit of a time crunch.
You should make a Transform struct that has a position, scale, rotation and a function to get the transformation mat4 from those. Then the physics engine can take this too and the colliders can stay in relative cords along with the meshes (or sdfs?)
@@Winterdev Hello, Thanks for this great video. I'm a big noob on both OpenGL and c++ but this inspired me a lot. Regarding your answer above, I have a question. When rendering say circles or spheres, the renderer will need both the position of that object, and the colliders 'center', and add them together, right? But I can't reach the variables radius and center from the class SphereCollider In my renderer as it simply interprets them as the base class "collider". Would I have to create a similar function-structure as you did with the colliders for the rendering or how does this work? any tips? Thanks, John. Edit: I mean, why is the "center" variable in the SphereCollider needed? can't it all be handled from the position in the transform? And the plane, can't it just be implicitly oriented with normal (1, 0, 0) and then let it's transform take care of any further rotations?
The trick is that the rendering world is separate from the physics world. You need to have some sort of object that represents the position and pass it to both, then they both add it to the colliders center and mesh verts. So everything is relatively positioned to a shared position.
The frozen code is in the article here blog.winter.dev/2020/designing-a-physics-engine/. And the working code is in the git repo here github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics
It's edited now, but here is the live code. github.com/IainWinter/IwEngine/tree/master/IwEngine/include/iw/physics github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics You can step back in time in the commits to find the og code.
@@Winterdev I'm trying to teach myself programming and makinga game in roblox and I learned basic scripting like scripting a part and achoring them some simple scripting but still its realy hard to understand I tried it but it didn't worked I got discouraged and now I ended up giving up.
@@RoidoStuff there are many tutorials available in RUclips. Learn c# and then use unity game engine or learn java and use android studio to make android apps and all.
I haven't watched the whole video yet, but your "pointer approach" to storing the physics objects is an obliteration of CPU cache and should not be used in production code.
If you're talking about applying forces, you'd do that in game logic with some collision event from a trigger for whatever region you wanted the force field in. Not too sure what you mean by 'response to continuous field' though
"This is the easy part and that's not what you've came for"... this guy really knows what is his target audience haha
i exist too!
and hence your statement is wrong
but i exactly came for that...im trying to make a solar system simulation xD
instablaster.
He just said that cause the title is about physics engines not engineless plain n-body simulations.
This is a really good approach for a code tutorial without telling the audience, which button they are supposed to press next. I love it!
Thanks!
Found this video per chance while searching for physics engines after giving up on writing my own.
Now I'm almost finished writing it. Thanks for the very well-explained overview! Definitely earned a sub from me.
Just came from The Cherno who says "use PhysX". Nah, my boy Winterdev don't need that.
Thanks for the truly excellent video!
Hell yeah! tyty
In all seriousness, this is gonna help me a lot, especially the part at 1:15, I've been making a game engine and wanted to fiddle with my own physics but didn't know how I should first mold it, and something basic like that (although translating it into a component) is perfect. Thanks so much.
Hey! I've been working on a rendering + physics engine for about 7 years now, not it takes that long to make it, but I went in and out of it as time passed and life allowed me to work on it. I'm definitely inspired by this video to create my own physics engine. Looking forward to the next video! :-).
I think you should do both. Continue with more videos on design and dive deeper into the math in another set of videos. I wish I had a video like this when I was pulling apart physics engines for the first time. This is a quality overview. Great job.
Thanks! You know what, I think that might just be the way. I could cover some of the algorithms that have few concise explanations. I bet I could make a good GJK video...
@@Winterdev GJK is an advanced and often poorly explained distance algorithm. To be meaningful it also requires an understanding of linear algebra and affine geometry. I'd like to see how you handle it.
I love the pacing and presentation! One of the very few videos that I had to slow down and rewatch at parts instead of speeding up
Well said
I did not know it was possible to show code in a video and keep it understandable, but you did it! Very nice video.
I'm a bit more interested in the math of e.g. what happens after a collision, or how to prevent errors in the simulation from building up and sending the spheres flying. But honestly I'll definitely watch the next video in the series, whatever it is!
Thanks! I'll get into that in the next part about physics. I don't have it planned, but when I get to it I'll lean a little bit more into the math. If you want to check out the code for the response, it's here and decently readable: github.com/IainWinter/IwEngine/blob/master/IwEngine/src/physics/Dynamics/ImpulseSolver.cpp
this is an amazing explanation I'm working on my own 'game engine' (more of a library than anything ) and I wanted to make a physic engine as a fun task, and this video explains things so well
Glad I could help :)
Can't wait for your next vid in this topic, amazing design & explanations!
Thanks! Next vid should be up in the next week or so, but it's about sand lol
I wish your videos had existed back when I started writing my own engines! I love how clean and neatly compartmentalised everything is!
Haha thanks, that is my goal, to make the tutorials that I needed. It seems I'm not the only one that wished there was clearer info on these topics! :)
Great video. Keep uploading this juicy stuff. Subbed.
Thanks! I'll try
This video is gold, thanks for breaking down your reasoning so well
Your videos are amazing. Very informative, easy to follow, and well thought through! :D Amazing job!
Thanks! I'm glad you find them clear :)
After watching the entire video, I remembered I don't know how to program.
Great video, this may get very useful. Making a physics engine seems a bit overkill, but I did already notice how it gives you a lot of freedom
Yeah plus a couple As in final school projects haha. And it’s fun to have a system that you know every detail of
How do you not have more subs??? Quality Content!
Brilliant video, I would love to see a video on the ECS you mentioned as I'm currently implementing my second iteration of a ECS and am curious to see how accomplish it. Keep up the good work
Thanks, I'll note that to do next after these sand vidz. That's prob not going to be for a while, but if you want to get some ideas the source code is here and not too messy, I think this was also my 2nd or 3rd go at it github.com/IainWinter/IwEngine/tree/master/IwEngine/include/iw/entity
That's was really good man!!
Bro this video was great, keep it up!
Only 2.5k subs? Criminally underrated channel
I found this extremely helpful in writing my own physics engine.
Dude amazing subbed with notifications!
great explanation!
will be cool to see more
Thanks! More videos coming soon, a new semester just started and I am bogged down with work though :
That... explains a lot... A while back, was trying to figure out why all the collision detection stuff was reactive to objects clipping together. Apparently, this is the norm.
I wonder if I can make it more proactive. Maybe with a raycast?
I got algorthmed here. Don't know who you are yet but this is great!
Thanks! It looks like its chosen me for today lol
Excellent video! Thanks for sharing
Thanks
When I made a physics engine as a university project I came up with a very similar structure myself. Code was a lot more mess) but the principle of collision solving was the same. The most challenging part btw was an angular motion
Really? I was under the impression that was only going to involve some slight edits lol. Looking forward to it now... :)
@@Winterdev Maybe it actually is a slight edit, I just could have done it extremely wrong xD Looking forward to your video about it to find that out)
Pretty cool overview, at least of the basics. Would be neat to see you integrate your GJK video with this video to create something a bit more realistic and useful than simple sphere vs. plane.
I'd check out the EPA one :p
Winterdev: Codes a physics engine in 5 minutes, provides glimpses of classes but doesn't provide the source code
Me: Can I see the full source code, so that I can run and experiment with it?
Winterdev: NOOOOO, don't you know how much TIME and hard work went into this??? How can you put such high expectations on me???
It’s in the article :p github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics
@@Winterdev Thank you, and sorry for the harsh comment, I just see a lot of bait on YT nowadays, trying to give ppl the false sense they've learned something when they've just made eyecandy for viewers
it's rare when someone talks about the real issues
excellent material, well done!
great vid
Thank you!
Trash you rud
I wish you could go over collisions a bit more, specifically broad phase collision detection
I am running into the limits of testing everything against everything right now, so once I make my version I can make a vid on that for sure!
This channel is a godsend. Thank you.
Wow. Thank you very much for this video!❤
Great video! loved it
Hey thanks a lot for your video ! I have two question :p
First: For the motion equation when you write [x=vt+x0] with [v=F/m*t + v0] I didn't get why when you integrate the velocity you don't have the 1/2 for the position.
because x should be equal to [x=F/m*t²/2+v0*t+x0] so you can't write [x=v*t+x0] or am I stupid ^^
Second: What do you use do make your formula and code animation ? :)
This was talked about quite a bit over on the hn page here news.ycombinator.com/item?id=24016718#up_24018883. It's a pretty interesting read. I've been using HTML and CSS for these 😂
Love the video! Can you do a full tutorial / code walkthrough of the impulse or position solver? I would love to know more of the math details
Thanks! Yes, I think I am going to throw that in with angular stuff when I get back to physics. The code is decently clear if you want to look at it github.com/IainWinter/IwEngine/blob/master/IwEngine/src/physics/Dynamics/ImpulseSolver.cpp
@@Winterdev Thanks I’ll try it.
Nice video! How are you creating this presentation? Are you using some specific software?
I just use a js file that switches classes around each ‘key frame’ and then I built another web tool that generates it
Great video! I’d love to know how all of this polymorphism affects performance. While it has a great design, I’m not sure that it will be performant, lots of dereferencing and dynamic function lookups. I’d think this would have terrible cache coherence.
The performance will be trash for more than the reasons you listed. Consider that every static object will need a collision test between every other static object, which is ridiculous. Which objects collide with which objects is something you need to tightly control (say, should a bullet interact with a gravity volume?) for performance and behavior reasons, and the approach in this video isn't good enough.
@@MisterFanwank Yeah one of my biggest regrets with this design was the double dispatch call. I later found a Valve pdf (page 33) that describes a 2d array of function pointers, then you use a ColliderType enum to index it. This lets you define all the possible collisions in one place and effectively centralizes the virtual function table. You could add another enum and follow this pattern for the object collision masks. The performance worked for my tiny games, but you definitely need a form of broad phase check/data structure for anything larger.
valve: pdf media.steampowered.com/apps/valve/2015/DirkGregorius_Contacts.pdf
Thanks for the cool video. Just curious, what are the reasons for writing your own physics engine rather than using open-source engines such as Bullet or Mujoco? Not saying you shouldn't do it, even out of interest, but are there any objective reasons to do it?
It started as a project for a physics class and then I realized I could use it for the simple games I was making. Over time I got invested in it :) I think other than coding exercises you should use a library, but I think it’s important to understand what the computer is doing so it’s def worth it to try and make one yourself.
Great work on explaining this in such a simple way! Would you mind clarifying what you meant by Position Solver and Impulse Solver? I didn't understand this part. Thanks!!
Thanks! They inhreit from 'Solver' and process each CollisionPoints. The idea is that the impluse one solves for the force of each collision, and the position once corrects the position directly for some error correction. You can check out the source of these here github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics/Dynamics
Question is that vector3 a thing in c++ or did you already create it or used a library?
No I made that myself. This didn’t need anything complicated math wise so I just made my own
@@Winterdev Oh is there the source code, or tutorial on how to do it?
There was but I’ve changed it form what it was for this project. For this all it was an x y z and operator+. In the collisions the dot product is used I think.
Your video is brilliant, it was a great pleasure to finally find someone explaining all that stuff in such a simple to understand format. I do have a stupid question for you, though. Don't get me wrong, but how did you get [ x = x0 + v∆t ] when describing uniformly accelerated motion? I mean, for that to be true, [ ∆x = v∆t ] would have to be true too, but [ ∆x = v0∆t + a∆t^2 / 2 ] (as was shown in the video)? I don't get why we calculate [ obj->Velocity += obj->Force / obj->Mass * dt ] and at the same time [obj->Position += obj->Velocity * dt]. Could you, please, at least briefly explain it in a reply to my comment, please? Thank you very much in advance
Thanks for the comment! Someone in the hacker news discussion was talking about that on similar lines news.ycombinator.com/item?id=24019099. My understanding is if you update the velocity then the position in the code, ∆x = ∆vt and ∆v = at. When you take the derivative you get ∆x = ∆v + a∆t^2 / 2. I think in the code if it were too update the position then the velocity, this would be an issue, but because the velocity gets updated then the position, those equations are equivalent.
@@Winterdev Thanks! Yeah, I guess the key is that we expect ∆t to be so small that we can afford getting some measurement error by calculating ∆x as if the object were moving uniformly without acceleration whatsoever. Also, like you said, this would be an issue if we calculated ∆x first, since then we would not really use acceleration anywhere at all. Thanks for clearing that up!
Great video! But I have a question, how did you do the graphycs of the video? Like the dynamics title and those trancitions. I want to do videos like this, but I don't know how to make them visually apealing
Uh, that's not a solar system, it's a bunch of balls floating in space. A solar system is a collection of masses orbiting a star. ._.
maybe the star is behind the camera :p
Don't forget quadtrees!
But where can we design a physic engine;Scratch, unity?
If you’re asking where to make something like this? Anywhere you can see the results! So you could print to console or use unity to easily display, tho that’s in C# not C++
Very interesting... thanks
Cool. What programming language are u using?
Thanks! And I used C++ for this
So I’m researching physics engines for racings games and I have a question if everyone can answer it (I haven’t fully watched the vid yet so bear with me) when it comes to making a racing game, for the cars to of course drive and drift. Is that done purely from coding in, the gravity, and friction from the wheels? So that once you brake the physics would cause the wheels to loose friction causing them to drift? I know that the wheels have their own collision, allowing the vehicles to drive. I just have no idea how it makes the car move and the thing that confuses me the most, drifting.
Well it depends on how realistic you want it. I’ve never made a racing game but you could do what you described or you could just have a simple obj following a path like Tube Slider
@@Winterdev I did some digging after leaving that comment and that is a common way to do it apparently when making physics for racing games. By having the wheels separate objects from the body, still attached of course, and giving them physics like friction and then just change them depending on what you want wether it’s a drag, drifter, or off-roader
Pretty neat but a little info and code on optimisation would have been really good.
thank you very much for this vide!
The Cherno sent me here.
Can you explain why 3:06 for SphereToPlane you pass a *tb Transform pointer as Plane Transform struct ? I cannot find this part of engine on github?
nice discovery, you should do tutorial on how to design a game engine bro
That's the long term goal! First I gotta finish this sand mini arc and then I want to go library by library and make vids like the first one
Very good video, I know you want to keep them short but feedback point I have is you are almost going a bit too fast (at least for my foreigner ears)
Thanks, I'm still getting that down, there are written versions as well so I don't really know if I should made fast videos or not... Here is the article if you're interested: blog.winter.dev/2020/designing-a-physics-engine/
...Is collision detection between primitives really as simple as separate functions for each possible interactions between all the different shapes? Is there not a better, more easily extended way to do this?
I changed it to be a table of function pointers later on which was much easier to work with. I don’t like the double dispatch at all looking back
Thank you
I noticed in the source of PositionSolver that you're displacing both colliding objects by resolution. Wouldn't it make more sense both objects only by half of it?
Yes that was a dumb mistake! Thanks for catching that :)
Going to make any more videos? How about a github link?
If you could, I would love to see a tutorial on implementing these things! The dynamic part was pretty easy but I've been trying the collision for days and it's constant errors and nothings working. I tried using the engine you're developing as a reference but its way ahead of where I'm at xD Im just not sure where to put the classes and stuff, any help is appreciated!
I don't know your specific code, but I'd try and start with something as simple as possible to get an idea for how it should come together/what the issues are.
You could start with making a 'Collider' that is just the sphere one because it's the more basic . Then you could store these in a list, really anywhere, and loop over them getting the responses if there is one and moving them by that response.
I might make a version of this with impl, but not for a while as I am trying out some other topics besides physics. gl with your code :)
@@Winterdev Thanks! I ended up getting it working but the plane collider is infinite along the x and z coordinates, did you run into that?
@@thebutterappletutorials6553 Yes that's what I have. Nice job!
@@Winterdev Thank you!!! Gonna move onto the Mesh Collider stuff next! (GJK and EPA) Would love to see videos going into the math (how to attach it to a custom model and have it work!)
Oh nice good luck!! When you say attaching it to a custom mesh, is that from a visible mesh to a physics one? Or any type of collider attached to whatever game object so they move together.
I would love to see how rigid body constrains work
Not a vid but here is a “3 fold poster” I made for a class final project. winter.dev/physics/ it’s not complete but a good start
Please dive deeper into the maths behind the implementations.
Could you please make the explanation but for Lagoa multiphysics algorithm? It's seems so much better than Bullet
So I was trying to follow along this, however I quickly ran into the issue of there being no vector3's (or vector 2's) in the std library or anywhere else, where are those coming form ? When trying to create them as a struct I can't do the needed maths with floats later on.
It’s a little unclear but those come from me. All you need for this are structs with 2 or 3 floats for x, y, z and maybe a length / dot product function which are both 1-2 lines so I didn’t cover that. I might add a small gist to the description
@@Winterdev A gist about it would be greatly appreciated, I for now created my own PhysVectors with the required coordinates and operators that should do for now.
Nice ;D
this was a good video, but you could've explained more on colliders
Thanks, if you watched my recent dev log I have these asteroids flying around that need the rotational collision response so I’ll make a vid covering colliders when I talk about that in a couple weeks
What is the best way to resolve 20k objects' collisions?
you need board phase with some spatial hashing
What about next video?
Funny enough, it's going up tomorrow :)
Does youtube keep deleting my comments? I'll try one more time.
Dynamics is more complicated than that. What you described here is the explicit euler method, which is unstable and unusable in physics engine. You might want to check out Erin Catto's 2015 GDC talk where he demonstrated the semi-implicit euler method, which most modern physics engines use.
Someone else was having their comments deleted too, idk why sorry. I watched that video and it looks like that I am using what's called semi-implicit Euler, which Eric concludes is the most common. That makes since to me because it's what you naturally end up with when translating the kinematic equations directly to code without thinking about it. Let me know if I missed something, thanks for the comment :)
What's this coded in (like visual studio or vscode, etc)?
I use visual studio but in theory you could use notepad lol. The build tools kinda abstract that away but I haven’t tested it with anything else
yeah imma just stick to using a physics library
Ok so I get the math of the physics engine, but how do you visualize it? I tried setting up OpenGL but now I am hours into getting that to run and take a simple input when i wanted to build a physics engine for fun lol.
Lol I feel your pain. OpenGL is as complex if not way more than the physics engine and impossible to debug if you don’t know where to look. I’d lookup GLFW which wraps all the nonsense (window/input/update loop) up for you, but you still need to pass a mesh by hand and have shaders setup. Maybe look for a renderer library that is made to be as simple as possible
@@Winterdev yeah in using GLFW. I'm a first year undergraduate computer science student. I built a ray Tracer and thought "all this math was cool, I should make a simple little physics engine." I think I'm gonna be able to understand GLFW and the physics but combining them might be problematic, I will figure it out! Or not, I have an internship starting next week so bit of a time crunch.
You should make a Transform struct that has a position, scale, rotation and a function to get the transformation mat4 from those. Then the physics engine can take this too and the colliders can stay in relative cords along with the meshes (or sdfs?)
@@Winterdev Hello, Thanks for this great video. I'm a big noob on both OpenGL and c++ but this inspired me a lot. Regarding your answer above, I have a question. When rendering say circles or spheres, the renderer will need both the position of that object, and the colliders 'center', and add them together, right? But I can't reach the variables radius and center from the class SphereCollider In my renderer as it simply interprets them as the base class "collider". Would I have to create a similar function-structure as you did with the colliders for the rendering or how does this work? any tips? Thanks, John.
Edit: I mean, why is the "center" variable in the SphereCollider needed? can't it all be handled from the position in the transform? And the plane, can't it just be implicitly oriented with normal (1, 0, 0) and then let it's transform take care of any further rotations?
The trick is that the rendering world is separate from the physics world. You need to have some sort of object that represents the position and pass it to both, then they both add it to the colliders center and mesh verts. So everything is relatively positioned to a shared position.
what program is this?
many lines of C++ called wEngine
how do you construct your vector3 union/struct/class?
It’s just 3 floats and you pass it x,y,z or it defaults to 0,0,0
Hi, can we use GJK collision detection
Yes I did a video on it :)
f += m * g
This only works if you zero f at the beginning, how it looks like in the code snippet, it should be f = m * g, small bug
Aa it does get 0’ed I don’t think I mentioned that tho. Good catch
I come from the algorithm, and i must say. Yes me likey applied math
Can you provide the source code for this?
The frozen code is in the article here blog.winter.dev/2020/designing-a-physics-engine/. And the working code is in the git repo here github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics
If you see this comment before this video have a million views you are a legend!
spotted
Where is the source?
It's edited now, but here is the live code.
github.com/IainWinter/IwEngine/tree/master/IwEngine/include/iw/physics
github.com/IainWinter/IwEngine/tree/master/IwEngine/src/physics
You can step back in time in the commits to find the og code.
meaty voice :weary:
(;´༎ຶД༎ຶ`)
you OOPed that code too much.
I'm far too deep in the mindset to turn back now lol :(
I always wanted to be a developer but mom can't afford to get me to a teacher
:(
@@Winterdev I'm trying to teach myself programming and makinga game in roblox and I learned basic scripting like scripting a part and achoring them some simple scripting but still its realy hard to understand I tried it but it didn't worked I got discouraged and now I ended up giving up.
@@RoidoStuff there are many tutorials available in RUclips. Learn c# and then use unity game engine or learn java and use android studio to make android apps and all.
@@ahmedaghadi8281 yeah I've been working on many games rn on roblox and I also learned some basic scripts
dive!!!!!
i love you
Too much stuff to understand for my small brain.
I haven't watched the whole video yet, but your "pointer approach" to storing the physics objects is an obliteration of CPU cache and should not be used in production code.
Yeah it’s up to you to allocate them efficiently. I’m not sure what box2d is doing with proxies but that might be cool to look at for a 3rd option.
I might sound silly but can we have a python version of this😅
nay
you should try it ;)
Good video, and I could understand it. But... However... Why are you speaking as fast as possible without any space between your sentences?
Eeeh, you forget about response to continous field...
If you're talking about applying forces, you'd do that in game logic with some collision event from a trigger for whatever region you wanted the force field in. Not too sure what you mean by 'response to continuous field' though
The link of your blog is dead
Thanks for point that out, it’s back up!
@@Winterdev Ok I confirm it's working back :)
I hate Minkowski