Writing a Physics Engine from scratch

Sdílet
Vložit
  • čas přidán 14. 04. 2022
  • Github github.com/johnBuffer/VerletSFML
    Music used pixabay.com/music/ambient-min...
  • Věda a technologie

Komentáře • 508

  • @PezzzasWork
    @PezzzasWork  Před 2 lety +261

    There is an error at 3:04 at line 41: it should be (radius - 50.0f).
    Thanks to those who pointed it out to me!

    • @PezzzasWork
      @PezzzasWork  Před 2 lety +20

      @Vitor m the dt is not needed because here « velocity » is in fact the distance traveled since the last update so it’s already equivalent to velocity * dt

    • @ziyadcodes
      @ziyadcodes Před 2 lety +12

      Me after spending 4 hours of pure suffering to figure out the problem then figuring it out and being so proud of my self. Then moving both of my fingers up to see the comment section and realizing that the first comment is addressing the problem 😭😭😭😭😭😭😭😭😭. It's even worse when I realize that I have tests and that I should have spend that time studying 😭😭😭😭😭😭. Please edit the video to save people from suffering like that. Or maybe it's just me whose that stupid |(>_

    • @TetyLike3
      @TetyLike3 Před rokem

      @@ziyadcodes sorry not sorry ¯\_(ツ)_/¯

    • @wiking2888
      @wiking2888 Před rokem

      Thank you soooo much I finally have it working

    • @oamioxmocliox8082
      @oamioxmocliox8082 Před rokem

      ;)

  • @AngeTheGreat
    @AngeTheGreat Před 2 lety +148

    I like how it really doesn't take much to create an amazing looking result (as long as you know what to actually implement of course). Nice video!

    • @PezzzasWork
      @PezzzasWork  Před 2 lety +17

      Thank you! And thank you for your videos as well, I found your channel very recently and I really like what you are doing! it seems that we have common interests :)

    • @PezzzasWork
      @PezzzasWork  Před 2 lety +9

      Waiting for your next video as well! (And btw the video on bloom was amazing)

    • @LineOfThy
      @LineOfThy Před 9 měsíci +3

      engine guy :D

  • @yell9140
    @yell9140 Před 2 lety +380

    My understanding of the code is currently too limited, but I will definitely learn and come back to this amazing video, I have always wanted to do things like that. Amazing work again Pezzza, wish you all the best.

    • @mickyr171
      @mickyr171 Před 2 lety +17

      I dont even know what language it is lol, i was thinking C++ but not 100%

    • @mickyr171
      @mickyr171 Před 2 lety +5

      Maybe rust

    • @PezzzasWork
      @PezzzasWork  Před 2 lety +53

      It’s indeed C++ :)

    • @mickyr171
      @mickyr171 Před 2 lety +8

      @@PezzzasWork thought so, I'm more a java/c# man myself, want to learn c++ but struggle to wrap my head around some of the functions

    • @PezzzasWork
      @PezzzasWork  Před 2 lety +29

      C++ is a big and complex language, it's not easy to get into it

  • @stylextv
    @stylextv Před 2 lety +273

    The colored circles at the end turning into your logo was pretty bad ass. How was it done though? Running the simulation to see where each object ends up then running the simulation again and coloring each object based on its final resting point?

    • @themikek99
      @themikek99 Před 2 lety +15

      Maybe it's reversed? B)

    • @khatharrmalkavian3306
      @khatharrmalkavian3306 Před 2 lety +76

      @@themikek99 Possibly, but Verlet integration is lossy when you add collision handling, so it would have to be a different process in order to be reversible.
      I think Stylex may have the right idea there. The process is entirely deterministic, so with the same conditions you'll always get the same outcome. You could run the simulation once, take note of where each object ends up, then color them accordingly, and re-run the sim to get the logo.

    • @gytiskau1865
      @gytiskau1865 Před 2 lety +55

      @@khatharrmalkavian3306 You could also bake the whole simulation, color the outcome and replay

    • @vacucumber_enjoyer
      @vacucumber_enjoyer Před 2 lety +2

      He probably read the image data and the. assigned the objects for some of the pixels and then gave them the velocity to make them move in the right way.

    • @GG64du02
      @GG64du02 Před 2 lety +3

      If he did not do it in reserve i am interested on how he pulled it off....

  • @NotAFoe
    @NotAFoe Před 2 lety +49

    Wow I love this kind of content so much, thanks pezzza!

  • @gaspardallimant1768
    @gaspardallimant1768 Před 2 lety +76

    How ?! It looks so easy to implement and the result is awesome ! Thank you so much, each of your videos is a bigger mindblowing for me than the previous one

    • @bigsmoke6414
      @bigsmoke6414 Před 2 lety +14

      I guess thats the Sebastian Lague Effect😉

    • @muuubiee
      @muuubiee Před 2 lety +8

      I suspect this is just the art of having studied some mathematics (multivariable calculus and linear algebra is probably enough).
      With math knowledge you can just take the equation and implement it.

  • @carrymeorgg8512
    @carrymeorgg8512 Před rokem +46

    You inspired me to learn C++ after fearing its complexity for months. I finally was able to learn C++ because of you. Please make more videos like this in the future. I enjoyed the teaching style and learned a lot. Keep up the great work man.

    • @PezzzasWork
      @PezzzasWork  Před rokem +12

      Thank you so much for your message, it is so cool to read ! I hope you will enjoy the possibilities that c++ offers! It’s a complex but very powerful language

    • @nejsonsvejson9861
      @nejsonsvejson9861 Před 11 měsíci +1

      Yeah, the hardest part of programming is overcoming the fear of complexity. It's what kept me away for years.

    • @MM2isBest
      @MM2isBest Před 12 dny +1

      So did you learn it carry?

  • @dragonminz602
    @dragonminz602 Před 2 lety +22

    Beautiful work and thank you for showing how you did it. That was very interesting.
    Also very cool ending

  • @americanhuman1848
    @americanhuman1848 Před rokem +15

    why struggle finding happiness when you can just watch this video? seriously its so relaxing and makes you feel like you have reached nirvana

  • @SuboptimalEng
    @SuboptimalEng Před 2 lety +33

    I'm really glad to have found your channel after Sebastian Lague made the ant simulation video. The stuff you make is amazing!

  • @bird5790
    @bird5790 Před rokem +1

    Please a part 2!
    this was by far the most interesting and ACTUALLY HELPFUL video i have seen in a while

  • @general3978
    @general3978 Před rokem +10

    This video is a masterpiece in technical execution and artistry

  • @alliepiper4772
    @alliepiper4772 Před 2 lety +5

    This is really cool, I always learn something new watching your videos! Implementing collisions and constraints by simply updating positions and having an integration function that can figure out velocity/acceleration is powerfully clever. Great explanation at the beginning, and the surprise picture at the end was a nice touch.
    Looking forward to your next adventure :)

  • @nothingnothing1799
    @nothingnothing1799 Před 2 lety +12

    I love the inclusion of the code itself seeing what it does is cool but being able to see how it was made is very cool imo

  • @alexhooper27
    @alexhooper27 Před rokem +1

    I always finish your videos in awe. This is what I aspire to be able to do with my knowledge of math and coding.

  • @spencer__
    @spencer__ Před rokem +1

    No idea how you made a physics programming video both beatiful and relaxing. Amazing work.

  • @user-tr2hc2xx3b
    @user-tr2hc2xx3b Před 2 lety

    Wow, looks so simple and elegant! Great job, looking forward to more videos like this one!

  • @movingheadmau8128
    @movingheadmau8128 Před 2 lety +1

    Always love watching your videos for the cool content you tackle :)

  • @singularityoptimist
    @singularityoptimist Před rokem

    Excellent work and a beautiful result

  • @sushismitcher225
    @sushismitcher225 Před 3 měsíci +1

    Wow!
    Incredible. I can't believe how elegantly and simply you set up the code for a complex-looking and incredible result. I also can't believe how you fit this into a 9min video. You're incredible.

  • @cirogarcia8958
    @cirogarcia8958 Před 2 lety +29

    It's amazing! You just taught me in less than 10 minutes what I wasn't able to learn on my own in weeks!
    Do you plan on uploading more videos like this in the future? It would be amazing to see how you deal with problems like tunnelling and static collision shapes

  • @sierpinskibrot
    @sierpinskibrot Před rokem

    Phenomenal work ur doing here man

  • @rtsa4633
    @rtsa4633 Před rokem

    This video is gold and I will definitely have to come back to it in the future if I build something like this

  • @kikawet
    @kikawet Před 2 lety +2

    I loved the video and really respect this channel! if you do a version with continuous collision detection then there is nothing more to expect from you!

  • @gigaprofisi
    @gigaprofisi Před rokem

    will never regret subscribing to this amazing and talented channel

  • @mementomori7160
    @mementomori7160 Před 2 lety +1

    I'm glad I subscribed to you, this vid made me really interested in making my own physic engine

  • @leod6011
    @leod6011 Před 9 měsíci

    Cheers to that bro

  • @eboatwright_
    @eboatwright_ Před 2 lety +3

    This is amazing! Thank you so much for your help! I've always wanted to make a physics engine, and I'll definitely implement this in Rust! :D

  • @dandymcgee
    @dandymcgee Před 2 lety

    Very cool demonstration. Great work.

  • @valet_noir
    @valet_noir Před 2 lety

    Love ur content, great to see a "behind the simulation" video ! Amazing :D

  • @newcooldiscoveries5711

    Unreal! Very Enjoyable! Thank You!

  • @aleksandarstankovic4476

    This video greatly benefits my coding skills! Thank you for the explenation!

  • @jamesking2439
    @jamesking2439 Před 2 lety

    Wow, I was convinced you needed both a position and velocity solver. Time to rewrite my engine. Thanks for sharing this!

  • @NimsoStudios
    @NimsoStudios Před rokem +4

    Bravo my friend, Bravo!
    An excellent look at the basic Velocity per frame physics engine and just how powerful circle collisions can be.
    I spent a moment trying to figure out why the velocity was updating before realising you were actually calculating it each step rather than keeping it persistent throughout.
    I'm going to play a little with the idea of calculating Velocity before applying motion to it, in 3D though since I work a lot on 3D character control systems and write the motion custom.
    This has been visually the nicest way to show the beauty of a physics engine.

    • @PezzzasWork
      @PezzzasWork  Před rokem +1

      Thank you very much! This should be directly transposable to 3D. I think it’s a good fit for what you are trying to do!

    • @NimsoStudios
      @NimsoStudios Před rokem +1

      @@PezzzasWork I do plenty of platformer gameplay systems, but usually keep velocity persistent rather than calculate immediately before applying the new step.
      Definitely something I want to try out, might end up making some cool stuff out of it too.

  • @softpaw6234
    @softpaw6234 Před 2 lety +1

    These simulations would have made great screensavers back when we needed those

  • @JosephCatrambone
    @JosephCatrambone Před 2 lety

    Good choice of music. Nicely demoed. Solid video.

  • @sanderbos4243
    @sanderbos4243 Před 2 lety

    Amazing tutorial, and the ending was such a twist!

  • @akosszabo3163
    @akosszabo3163 Před rokem +2

    Your work is very impressive. Thanks for the video. It motivated me to implement this on the language I know the most, so I implemented it in Java. Finally after a couple of hours it worked fine. I implemented all the functions you demonstrated. Functions can be initiated from the menu. Additionally based on the chain example I implemented a rigid body. The last function will be the magic. You can open a picture and cut a part of it and that will appear as your logo did. I will share it as soon as it is done. So thanks again, nice job!

  • @GradientAscent_
    @GradientAscent_ Před rokem

    Love these endings, keep it up

  • @markwinfield845
    @markwinfield845 Před 8 měsíci

    Great video, I am subscribing.

  • @NeverForgetNasa
    @NeverForgetNasa Před rokem

    Oh my god, that is so beautiful.

  • @_7OwO7_
    @_7OwO7_ Před 9 měsíci

    Beautiful

  • @duongquanghuy4387
    @duongquanghuy4387 Před 2 lety

    The ending got me. Nice work!

  • @xvitxr
    @xvitxr Před rokem +1

    bro, this video is a masterpiece, my dream is to be a developer like you.
    i saw all your past and recent videos and every one of them are amazing!
    please, PLEASE keep the good work

  • @LogInValid
    @LogInValid Před 2 lety

    This makes me want to go back to school and learn programming. Simply Amazing!

  • @caoduythanh1453
    @caoduythanh1453 Před 2 lety

    what a master piece!

  • @Rentaro_dev
    @Rentaro_dev Před 2 lety

    Nice video man! A wiki article and your video helped me very much.

  • @henwill8
    @henwill8 Před 2 lety

    Wow it literally felt like magic how it just simply worked with such little effort and code

  • @NoxiusVI
    @NoxiusVI Před rokem

    Amazing tutorial! Worked really well even when using a different language!

  • @mariusvanc
    @mariusvanc Před rokem +10

    5:40 I was thinking the "perfect" solution to this would be, aside from sub-stepping, to add a bit of friction every time there is a collision, this would settle the objects quicker so they don't vibrate while stationary. Just multiply the vectors by 0.99 or something like that.

  • @nikbivation
    @nikbivation Před rokem

    thank you for this!

  • @redspyro4750
    @redspyro4750 Před rokem

    I don't even know much about code, so this is already very helpful! And by helpful I mean I will probably keep rewatching this every time I want to do physics simulation.

  • @busy_beaver
    @busy_beaver Před 2 lety

    Thanks for this great video!

  • @michaberkowicz8239
    @michaberkowicz8239 Před 2 lety +7

    That ending was..... unexpected

  • @SpartanG318
    @SpartanG318 Před rokem +1

    I find you right that moment and i am a software engineer in trainee... i can understand the code a bit and on the other hand i sit here and think, i know nothing about physics and simulations. Pretty mind blowing your work. This Bonus at the end.... HOW?? Thanks man, i cant stop to smile. :)

  • @starship9874
    @starship9874 Před 2 lety

    This is the most underrated coding channel ever. Your videos are so high quality

  • @Katniss218
    @Katniss218 Před rokem +1

    The end was really cool!

  • @NStripleseven
    @NStripleseven Před měsícem

    The concept of Verlet integration is actually super cool IMO, because it means momentum changes from collisions/etc are handled more or less automatically.

  • @Reditect
    @Reditect Před rokem +1

    Amazing! I've been trying to understand the programming behind physics and make my own 2D and 3D game engines. Visually appealing and informative video. Thanks. :)

  • @williambarajas8090
    @williambarajas8090 Před 2 lety

    yes!!!!!!! love the video please make more of them!!!

  • @glumpfi
    @glumpfi Před 2 lety +1

    :O Especially the end blew me away!

  • @DevashishGuptaOfficial

    This video made my day!

  • @odedkadshai
    @odedkadshai Před rokem

    felt like magic show

  • @Chareidos
    @Chareidos Před rokem

    lol...
    was gonna write so many questions in another video, asking how to get there...
    now I found this clip before I would have sent that long comment!
    This is a clip to start with, I guess.
    Thank you for enabling me to at least try.
    Subscribed!
    Maybe you link this video clip in the notifications of other stuff you uploaded!

  • @and_I_am_Life_the_fixer_of_all

    that ending felt like an assembly theory flex before its time, wow.

  • @pelicannot.
    @pelicannot. Před 2 lety +10

    i love this channel :D

  • @Archangel2x
    @Archangel2x Před 2 lety

    The ending logo showing up was like magic.

  • @ArashRabbani
    @ArashRabbani Před rokem

    the jaw dropping last scene!!!

  • @brecoldyls
    @brecoldyls Před 11 měsíci +1

    Can’t wait for part 2: Writing a Physics Engine in Scratch

  • @prometheusli101
    @prometheusli101 Před 2 lety

    amazing effect

  • @WDGSWhatDoesGodSay
    @WDGSWhatDoesGodSay Před 2 lety +9

    OMG I have been trying to figure out how to make a physics "engine" like this from scratch.

    • @WDGSWhatDoesGodSay
      @WDGSWhatDoesGodSay Před 2 lety +1

      Can you make the .cpp files available in the description or tell me where I can find them. THANKYOU!!!

  • @HyperHrishiHD
    @HyperHrishiHD Před rokem

    You scared away half of the people away with the equation as the first thing in the video.
    But I’m all here for it

  • @devmarboy4045
    @devmarboy4045 Před rokem +1

    this is so sick, can’t wait to get as advanced as u lol

  • @jacktapping9290
    @jacktapping9290 Před 2 lety

    beautiful

  • @mctuble
    @mctuble Před rokem

    Just using the colors makes this so much better lol.

  • @expressoaddict
    @expressoaddict Před rokem

    That ending was lit.

  • @Sam-hu3xt
    @Sam-hu3xt Před rokem

    Three words: epic!

  • @rodakdev
    @rodakdev Před 2 lety +3

    That chicken has glasses for a reason! So cool!

  • @osartur
    @osartur Před 2 lety +10

    You must have worked really hard to get where you are. You are really good at what you do

    • @osartur
      @osartur Před 2 lety +7

      I used a translator so I don't know if what I said was strange 😁

    • @wilykary
      @wilykary Před 2 lety +1

      @@osartur nah not at all

    • @TetyLike3
      @TetyLike3 Před rokem

      @@osartur the only problem with that sentence was the punctuation lol

    • @pineapplerindm
      @pineapplerindm Před rokem

      @@TetyLike3 i dont see anything wrong with the punctuation

  • @bluesillybeard
    @bluesillybeard Před 9 měsíci +1

    I was literally trying to implement physics, then I though "wait a sec, Pezzza's Work as a video on that!"
    I'm surprised how well it works without even considering the forces between the objects or even their masses - it just moves the objects around based on an extremely simple set of rules.

  • @lorenzoassiro8532
    @lorenzoassiro8532 Před 2 lety

    Wow this code is mind blowing🤯

  • @user-lp8pq4en5u
    @user-lp8pq4en5u Před rokem

    excellent!!!!

  • @yudhistira7231
    @yudhistira7231 Před 2 lety

    Awesome dudeee, I never get bored watching your videos. A subscriber btw, keep it up!🏃

  • @VincePhoenix
    @VincePhoenix Před rokem

    Impressive !

  • @mr.milindsingh7671
    @mr.milindsingh7671 Před 9 dny

    This was fantastic. I loved the way you simply coded this complex looking problem. I was wondering what would it take if I wanted to add friction forces among particles.

  • @MrWandalen
    @MrWandalen Před 2 lety

    I love this

  • @simonsvoboda8849
    @simonsvoboda8849 Před 3 měsíci

    I'm so glad youtube recommended this video to me. How did I not know about this??

  • @Hailfire08
    @Hailfire08 Před 2 lety

    Awesome video!!!

  • @MrNucleosome
    @MrNucleosome Před 2 lety

    THANK YOU

  • @fahtenfuhten
    @fahtenfuhten Před rokem

    That was amazing!! I love your work very much!!! I'd love to create things like that!!! Where can someone start???

  • @Radu
    @Radu Před 2 lety

    Nice ending! It's the reason I subscribed :-)

  • @mathijswy
    @mathijswy Před 2 lety +3

    Whoa, that's amazing for entry projects. Is the code of the engine and physic imports available somewhere to play around with?

  • @vinaciotm
    @vinaciotm Před 9 měsíci

    THANKS A LOT!!! PLEASE, PART 2
    some ideas: (I really excited about)
    rotation/angle, applyForce, applyImpulse, box shape, custom shape(polygon, array of Vec2 stroke and fill

  • @unknown-bx8my
    @unknown-bx8my Před rokem

    awesome😍

  • @artemonstrick
    @artemonstrick Před 2 lety

    Fantastic

  • @JIMNORTON2008
    @JIMNORTON2008 Před rokem

    genius

  • @hierper7973
    @hierper7973 Před rokem

    what a great ending

  • @himanshubakshi5680
    @himanshubakshi5680 Před 2 lety +3

    I have a question, i tried to do this in python but inertia*Accelaration just ruined it, i edited it and tried my best also comparing it to verlet's integration. i have an equation Position+Inertia+Accelaration and i used accelaration as dt btw very nice channel for coders like me, helped me a lot making circle collusions
    BEST OF LUCK for your channel

  • @jellybean2427
    @jellybean2427 Před rokem

    You saved my life

  • @raushankumar2336
    @raushankumar2336 Před rokem

    I can't understand how thing is being applied, but i loved it especially the bonus clip 🔥
    I have to learn alot to achieve this, nevermind i will do that