I'm Coding an Entire Physics Engine from Scratch

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

ความคิดเห็น • 1.7K

  • @playerguy2
    @playerguy2 3 ปีที่แล้ว +9574

    Ah, the programmer's credo:
    "We do things not because they are easy, but because we thought they were going to be easy."

    • @themaster2764
      @themaster2764 3 ปีที่แล้ว +90

      ON POINT

    • @tex1297
      @tex1297 3 ปีที่แล้ว +48

      Not the programmers only👍

    • @fitmotheyap
      @fitmotheyap 3 ปีที่แล้ว +38

      Yeah that's about everything in a programmer's brain
      Then we see thousands of mistakes

    • @filipthunell8631
      @filipthunell8631 3 ปีที่แล้ว +34

      @@tex1297 literally just anyone working with stuff that involves a large amount of math

    • @tex1297
      @tex1297 3 ปีที่แล้ว +15

      @@filipthunell8631 right +any creative people of any field

  • @georgplaz
    @georgplaz ปีที่แล้ว +148

    imagine how many cool libraries we wouldn't have if the authors had realized how much effort it would be

  • @naturally_rob
    @naturally_rob 3 ปีที่แล้ว +6602

    "I can probably do it better" every programmer, hell, every person creating something says this and immediately regrets their decision until it's complete

    • @ЭнрикеЧурин
      @ЭнрикеЧурин 3 ปีที่แล้ว +241

      It's the only thing that keeps world from not using 500 year old software lol

    • @TurboBorsuk
      @TurboBorsuk 3 ปีที่แล้ว +21

      Instead, we have e.g. JS frameworks mess, being flooded by D-K syndrome folks on one hand and driven by shiny object syndrome folks on the other :P

    • @tomsterbg8130
      @tomsterbg8130 3 ปีที่แล้ว +24

      I remember that I was still with only 2 years of experience on Roblox Lua when I saw that time's best vehicle module. I wasted a month or two trying to make a better one just to abandon it and realise that I can do it now, but if I attempt it's not even going to benefit me in any way.

    • @dimaryk11
      @dimaryk11 3 ปีที่แล้ว +9

      Except that's how innovation is done

    • @naturally_rob
      @naturally_rob 3 ปีที่แล้ว +6

      @@dimaryk11 not always but sometimes it does result in innovation.

  • @chandler7453
    @chandler7453 2 ปีที่แล้ว +64

    I was cracking up at 8:53. So that's how a bouncy ball behaves when it exists in an atmosphere that somehow lacks entropy.

    • @chandler7453
      @chandler7453 2 ปีที่แล้ว +6

      You could probably achieve more stability if you could somehow make the ball leave an imprint of its momentum on any object it comes into contact with, on the understanding that contact between two objects must achieve a null state before contact is broken (like with objects that are artificially forced into place, like walls that hang in the air, returning equivalent negative values). In nature, we are supposed to subtract the influence of the struck object(s) from the original trajectory of the striking object to find its path through space. If we don't, the moving object inherits that extra energy of being struck back by the wall and internalizes it, without losing any of its original velocity, causing the structure to eventually warble out of control the longer it moves.
      I don't know how it works in code, though.

    • @matthewscott336
      @matthewscott336 ปีที่แล้ว +12

      Oh right. So his sphere heated up.

    • @chandler7453
      @chandler7453 ปีที่แล้ว +5

      @@matthewscott336 that's the best way to say it

  • @alengm
    @alengm 3 ปีที่แล้ว +3953

    I did physics sim stuff too (and want to do more) and it seems like our brains are of similar smoothness, so I understand your pain. It's comforting to see someone else struggle with the same stuff.

    • @Particelomen
      @Particelomen 3 ปีที่แล้ว +58

      Can only agree! I'm working with an advanced optics sim at the moment and some days I just wish I could close my eyes and forget my existence for a little while... But when it works, then it's all worth it again!

    • @HarshRajAlwaysfree
      @HarshRajAlwaysfree 3 ปีที่แล้ว +74

      i dont even code, im a civil engineering student
      just come here to see people in pain and having fun

    • @hetoPerero
      @hetoPerero 3 ปีที่แล้ว +3

      ahhhhh one of my kind

    • @theweirdshow2860
      @theweirdshow2860 3 ปีที่แล้ว +1

      Smart minds think alike

    • @MrMultiMediat0r
      @MrMultiMediat0r 3 ปีที่แล้ว

      Subbed

  • @Mshagy02
    @Mshagy02 2 ปีที่แล้ว +27

    8:10 why does the ball look like the coronavirus 💀

  • @kpberry11
    @kpberry11 3 ปีที่แล้ว +2441

    I think you need some damping/friction forces. It looks like the springs in the ball are perfectly elastic right now, so each impact will just increase the internal pressure, causing each triangular section to oscillate more and more (like simple harmonic motion, but complicated since it's in a connected mesh of springs). Dissipating the energy as "heat" should keep the ball's internal pressure more stable and prevent the triangular sections from vibrating faster and faster.

    • @blinded6502
      @blinded6502 3 ปีที่แล้ว +108

      At high enough friction/viscousity this ball will behave like a solid object, by the way.

    • @gaussgreen7921
      @gaussgreen7921 3 ปีที่แล้ว +66

      @@blinded6502 with explicit integration it wont ever be able to use a high enough viscosity/stiffness to make it behave like a rigid body.

    • @gimmethedata4256
      @gimmethedata4256 3 ปีที่แล้ว +17

      Yeah I think they should have some friction relatively to the other points. If they go against the stream then friction. Have fun! xD

    • @blinded6502
      @blinded6502 3 ปีที่แล้ว +10

      @@gaussgreen7921 Of course. Unless you advance simulation by very tiny time intervals, and possibly even increase precision of the coordinate system.

    • @Adraria8
      @Adraria8 3 ปีที่แล้ว +70

      Yeah also the imperfections of solving the differential equations numerically could be causing a feedback loop of growing energy in the springs

  • @gorkaeze9038
    @gorkaeze9038 2 ปีที่แล้ว +14

    3:07
    Hexagons, are the bestagons

  • @noodl5138
    @noodl5138 3 ปีที่แล้ว +1540

    When I first read the title I thought it said "Coding an entire physics engine IN scratch", that would have been insane

    • @votoxp
      @votoxp 3 ปีที่แล้ว +63

      Omg same so now i sad

    • @meehdrescher
      @meehdrescher 3 ปีที่แล้ว +13

      oooauaiaiaiaiauauauaauauauauau how to unread things

    • @katteisace4563
      @katteisace4563 3 ปีที่แล้ว +38

      @Biglyp people have made 3d stuff in scratch

    • @bendysans1077
      @bendysans1077 3 ปีที่แล้ว +5

      @@katteisace4563 yeah buts it’s not true 3D

    • @duckhuntdawg
      @duckhuntdawg 3 ปีที่แล้ว +4

      same

  • @Luizfernando-dm2rf
    @Luizfernando-dm2rf 2 ปีที่แล้ว +9

    That epic montage was amazing, it captures every aspect of "learning" a new skill :´)

  • @IIIIIawesIIIII
    @IIIIIawesIIIII 3 ปีที่แล้ว +373

    #1) There seems to be not enough decay to the energy in the springs
    #2) The Energy is stored in the single springs and not dissipated to the other springs, allowing for resonance. And as those who resonate more will re-collide earlier, there is a positive feedback loop to this resonance.

    • @Chingus621
      @Chingus621 ปีที่แล้ว +10

      Ok science boy

    • @ulukoruetc
      @ulukoruetc ปีที่แล้ว

      I am not sure about this but do you adjust the area in the force formula, according with the mesh count?

    • @beckcherry
      @beckcherry ปีที่แล้ว +13

      It just might be that there’s no damping at all

    • @sitter2207
      @sitter2207 ปีที่แล้ว

      nerd

    • @cat47
      @cat47 ปีที่แล้ว

      when are you gonna upload on your yt channel again? your songs are very nice

  • @zelo_s6707
    @zelo_s6707 2 ปีที่แล้ว +7

    This dude's got some hilarious editing. Keep it up!

  • @intuitivamkt
    @intuitivamkt 3 ปีที่แล้ว +471

    lets all just take a moment to aprecciate the devs of the simulation we live in

    • @motherisape
      @motherisape 2 ปีที่แล้ว +20

      Thanks 😊 . I will not delete your soul until you are 90 year old

    • @intuitivamkt
      @intuitivamkt 2 ปีที่แล้ว +7

      @@motherisape can you boost me so that I look like I'm 50 when I'm 90?

    • @casualbydefault
      @casualbydefault 2 ปีที่แล้ว +32

      @@motherisape Yo, Tell the guy who created my code that his choice of skill point distribution sucks.

    • @egg-iu3fe
      @egg-iu3fe 2 ปีที่แล้ว +5

      imagine having to code all the quantum particles and then atoms and physics and complexity of this universe, those beings may as well be gods compared to us

    • @ICantThinkOfAFunnyHandle
      @ICantThinkOfAFunnyHandle 2 ปีที่แล้ว +2

      @@casualbydefault my bad, we accidentally used an older version of the skill point distribution algorithm when we made you

  • @ozzeybek
    @ozzeybek 2 ปีที่แล้ว +3

    I’m a business major and I still enjoyed the video. Good humor & editing, keep it up!

  • @NNOTM
    @NNOTM 3 ปีที่แล้ว +507

    Disclaimer: I know very little about numerical integration. But maybe using a symplectic integrator (e.g. velocity verlet) instead of Runge-Kutta would help with the oscillations you're getting.

    • @Gonkee
      @Gonkee  3 ปีที่แล้ว +133

      What, I thought RK4 was meant to be the best one

    • @NNOTM
      @NNOTM 3 ปีที่แล้ว +104

      ​@@Gonkee Depends on how you define "best", there's always pros and cons

    • @NNOTM
      @NNOTM 3 ปีที่แล้ว +35

      @@Gonkee Also there are symplectic versions of Runge-Kutta fwiw

    • @A.A.H-
      @A.A.H- 3 ปีที่แล้ว +94

      @@Gonkee Although RK4 is a big improvement on Euler method, and is good enough most of the time, it still can be improved (usually in the cost of computing effort and complexity of the algorithm).
      Specifically, at 7:10, as a result of increasing the spring coefficient to 999999, the solution probably now have very high gradients and your time-step is probably not small enough to capture it and the solution completely diverges. In the Numeric Analysis world, we say the problem/equation is "stiff".
      If you want to somewhat keep the simplicity of the integrator, you might be interested in the adaptive RK45 method. If you are willing to invest in more complex methods, maybe consider researching into implicit RK methods.
      This is the first time I hear about the Verlet's method proposed above, but maybe it's also a good fit.
      Disclaimer: I never used implicit RK methods, but I heard from a professor that they are used to solve stiff problem.

    • @luis_musik
      @luis_musik 3 ปีที่แล้ว +10

      @@Gonkee i think the problem is that you're trying to solve a set of partial differential equations by treating each PDE as a separate ODE. im by no means an expert but afaik there are algorithms designed for solving PDEs that are much more stable

  • @commandresswhiplash98
    @commandresswhiplash98 2 ปีที่แล้ว +2

    Hey Gonkee, I came across your video some time ago and it inspired me so much. I loved seeing your entire raw process, struggling and learning an entire language from scratch. It gave me a huge motivation boost and made me realise that it's possible to pull off something as crazy as this through sheer will. Thanks a lot for this. You're a genius.

  • @calitts4708
    @calitts4708 3 ปีที่แล้ว +161

    Amazing video. I love doing a funny and unnecessary project that takes part of my soul while I'm making it. Subscribed

  • @UkkosTukki
    @UkkosTukki 2 ปีที่แล้ว +3

    I feel your pain :) You still managed to code an awesome demo 💪

  • @pedritom100
    @pedritom100 3 ปีที่แล้ว +105

    Im in my first year in college studying software engineering and I thought chemistry was gonna be useless to me.. but I now saw you using the ideal gas formula and now I’m motivated to study 👍 thanks, and great video!

    • @MaxMustermann-bm7qt
      @MaxMustermann-bm7qt 2 ปีที่แล้ว +9

      You are new, to this. So I make an exception. The first rule of thermodynamics is: Noone talks about thermodynamics.

  • @RiverReeves23
    @RiverReeves23 2 ปีที่แล้ว +3

    Good stuff man. I'd find some Discord group with coders that geek out on physics and ask around. In the mean time, your video style is great.

  • @mahyellaw
    @mahyellaw 3 ปีที่แล้ว +49

    boredom really brings you to a journey of pain and suffering. amazing video as always man, i'm loving this format so far :D

  • @PoppinCorn
    @PoppinCorn 2 ปีที่แล้ว +7

    “it’s 2 weeks later, and i’ve probably lost 5 years off of my lifespan”
    ah yes, mathematics

  • @physicsteacher6633
    @physicsteacher6633 3 ปีที่แล้ว +39

    Thank you Gonkee. You have made all the pain of teaching physics worth it. I am thinking that I can use your video as motivation for my students. Would be great for the computational physics class that I taught a couple years ago. I do feel a bit guilty, that I can't go help fix your code right now. I'm sure you'll figure it out...you are the best type of student. Very proud of you young man.

  • @diniodo5898
    @diniodo5898 ปีที่แล้ว +1

    the points on the sphere accumulate kinetic energy when time passes with no way to get rid of it (that's why it might go haywire or "explode"). in the real world a ball in air and earth has more than 100 ways to get rid of this energy through collision and contacting. it's like the ball gets refreshed each time it does something but still hold on to its positional value and it's center of mass general velocity vector's direction. hope this physics fact inspire you.

  • @prosimulate
    @prosimulate 3 ปีที่แล้ว +20

    You got style, patience and brains man. Keep it up. I’m not even in this field but watching you think through the problems really made me smile. You’ll go far.

  • @litterbox019
    @litterbox019 2 ปีที่แล้ว +4

    3:20 "how to make an iron golem"
    what a gamer

  • @jacobryant2673
    @jacobryant2673 3 ปีที่แล้ว +46

    Gonkee: "I'm coding an entire physics engine from scratch"
    Me: "You poor poor soul"

  • @raveltammeleht6278
    @raveltammeleht6278 3 ปีที่แล้ว +2

    Nice video! Yeah Runge-Kutta 4... when I learned this, it was like cake and roses. Joking, it was like pain in my pineal gland. But I managed to get it working. It actually took me about a half a year to actually understand the papers of Runge-Kutta 4 and how to advance it. I mean you are taking one second and dividing it to pieces and then summarising the pieced simulations together and passing as a single second... But it sure does make a huge difference! I integrated it to my vehicle simulation and I actually had to rewrite about 90% of the simulation, just to make it compatible and there still are some minor issues, just like you are having haha. Maybe you can advance your soft body to a metal simulation, by adding some fading dampening, you could make a seriously cool damage system. Fluids are the hardest, would love to see how you approach it.

  • @Xbox360SlimFan
    @Xbox360SlimFan 3 ปีที่แล้ว +70

    1. Fix: (Not easy to implement)
    When solving the harmonic oscillators (these spring mass thingies in the icosphere) with an explicit scheme like RK4, the systems energy increases from numerical errors until it diverges to infinity. When solving with an implicit scheme (much harder to implement), the systems energy converges to zero and is therefore to be preferred.
    2. Fix: (Turbo easy to implement)
    I assume You did not implement a damping term. In reality, a pendulum or an oscillator never oscillates for ever, it loses energy due to friction and shit. If You include a small damping term into the oscillators You will see iz gunna wok.
    3. Fix: (Bruh)
    Just decrease the time step size. The RK4 scheme should do better at 120Hz or 240Hz.
    He actually implemented a daming term in 6:07
    The parameter 'dampingConstant' is probably set too low - much too low

    • @madmax43v3r
      @madmax43v3r 2 ปีที่แล้ว

      A high damping coefficient will make it go boom too, the more force is generated the smaller your timestep has to be to keep it stable.

    • @Xbox360SlimFan
      @Xbox360SlimFan 2 ปีที่แล้ว

      ​@@madmax43v3r Yep:
      If the step size is too large on an explicit scheme, everything goes boom.
      There are situations where a damping term generates a converging solution.

    • @TheRainHarvester
      @TheRainHarvester 2 ปีที่แล้ว

      Would using double floats help? (It helped on my micro gravity videos... Kept 1/r2 from going to infinity at smaller proton scales.)

    • @Xbox360SlimFan
      @Xbox360SlimFan 2 ปีที่แล้ว +3

      ​@@TheRainHarvester In this case:
      The machine error is orders of magnitudes smaller than then error of the integration scheme.
      => Doubles would probably not make a significant difference.
      In Your case:
      The major source of errors was the machine accuracy for small float numbers. Hence, double precision solves the issue.

    • @TheRainHarvester
      @TheRainHarvester 2 ปีที่แล้ว

      @@Xbox360SlimFan I'm dealing with integration errors now: unequal approach and departure simulation ticks.

  • @DRZME400
    @DRZME400 2 ปีที่แล้ว +1

    dude. great video. You're a sadist...and I love it, because this is educational and fun (and super funny (I LOL'd a ton))! Also subbed

  • @user-sl6gn1ss8p
    @user-sl6gn1ss8p 3 ปีที่แล้ว +45

    7:40 as someone who took numerical integration classes from physicists, good luck with that : p

    • @Gonkee
      @Gonkee  3 ปีที่แล้ว +16

      Oh no you make it sound like it'll be a terrible experience

    • @siegfriedkettlitz6529
      @siegfriedkettlitz6529 3 ปีที่แล้ว +6

      @@Gonkee It will.

    • @user-sl6gn1ss8p
      @user-sl6gn1ss8p 3 ปีที่แล้ว +4

      @@Gonkee to be honest, it's kind of a coin-flip in my experience, but when it's bad it's really bad

  • @shmiooo
    @shmiooo 2 ปีที่แล้ว

    I’ve stumbled upon your channel & have never been happier. 1 minute into this video and you have me cracking up

  • @creepager1510
    @creepager1510 3 ปีที่แล้ว +468

    I laughed my ass of. I don't care how good or bad this actually is, it's the funniest shit watching

    • @progamerdylanabel4189
      @progamerdylanabel4189 2 ปีที่แล้ว +6

      Is it just me or is that comment T H I C..
      Dani: no not now I’m working on karlson

    • @Jake2534
      @Jake2534 ปีที่แล้ว +1

      CREEPER MAN

    • @creepager1510
      @creepager1510 ปีที่แล้ว +1

      @@Jake2534 yoooo

  • @gustavoespinoza7940
    @gustavoespinoza7940 2 ปีที่แล้ว +1

    The ball exploded because the time step wasn’t small enough to equilibrate/mesh grid wasn’t small enough.
    To get it to not blow up you can decrease time step to small small
    Increase nodes
    Adjust the equilibrium position on the springs
    Alternatively you can use an FOV average to assign values to your ball as opposed to using a spring mass system.

    • @gustavoespinoza7940
      @gustavoespinoza7940 2 ปีที่แล้ว

      Or you can also implement a mesh that changes over time

  • @dalkos6
    @dalkos6 3 ปีที่แล้ว +170

    I like how his equation for the ideal gas constant has all the capital letters for FART in the right order at 5:35

    • @xXJ4FARGAMERXx
      @xXJ4FARGAMERXx 3 ปีที่แล้ว +7

      "How many of the average person's fart gasses are needed to make the pressure in an ico sphere go from 1 atmospheric pressure to 2 atmospheric pressure?"

    • @atharvparlikar8765
      @atharvparlikar8765 3 ปีที่แล้ว +6

      @@xXJ4FARGAMERXx a lot

    • @awwomegrasscalledalfalfa6437
      @awwomegrasscalledalfalfa6437 3 ปีที่แล้ว

      damn

    • @trentSMC
      @trentSMC 3 ปีที่แล้ว

      @@xXJ4FARGAMERXx that is a genius question. I don’t know why the worlds best scientists aren’t working on it now. Or maybe they are…

    • @WD_RatLad
      @WD_RatLad ปีที่แล้ว +1

      @@xXJ4FARGAMERXxhaha text in between username go brrrrr

  • @venusisalwaysabove
    @venusisalwaysabove 2 ปีที่แล้ว

    First time watching your video, you have done a remarkable job. I'm sure your channel will stand out as it is already.

  • @PatrickHoodDaniel
    @PatrickHoodDaniel 3 ปีที่แล้ว +5

    You have an awesome and interesting way of communicating your ideas and experience. I would love to see some NN, or other machine learning subjects tackled by you.

  • @eboatwright_
    @eboatwright_ 2 ปีที่แล้ว +2

    This is amazing! (I also want to make my own physics engine :)) Also, it's really cool how your new channel is *already* more popular than your old one :O

  • @Bozeman42
    @Bozeman42 3 ปีที่แล้ว +20

    This makes me feel way better about my spring-mass system I made. It ALSO was sensitive to the parameters and exploded in a very similar way :)

  • @danieldinnie5003
    @danieldinnie5003 2 ปีที่แล้ว

    Nice one bro. That's an awesome project. During lockdown, I decided to make a program that tries to predict which stocks are going up and down. Programmers be crazy...

  • @cp-st5er
    @cp-st5er 3 ปีที่แล้ว +13

    Can’t wait to see the next update video! It looks like a really cool project.

  • @Seabass_E
    @Seabass_E 2 ปีที่แล้ว +1

    Dude, you are hilarious and I have so much respect for you doing this!

  • @ElVerdaderoAbejorro
    @ElVerdaderoAbejorro 3 ปีที่แล้ว +5

    Your humor is spot on and your content quite unique. Subscribed.

  • @abdelkefiali440
    @abdelkefiali440 3 ปีที่แล้ว

    Vids like this motivated me to code,thanks buddy

  • @UnrealMatter
    @UnrealMatter 3 ปีที่แล้ว +13

    As a CGI Artist I have to say you made it insanely good! Nice work because you did it alone and didn't knew stuff about it before.

  • @xxneweraxx7422
    @xxneweraxx7422 2 ปีที่แล้ว

    Bro, ur insane. I love that type of humor so much, the editing is well paced and those random images there and here alongside all the dumb memes, that shit is insane. Keep going on, the content is insane as well man

  • @theRPGmaster
    @theRPGmaster 3 ปีที่แล้ว +33

    It's truly a joy to see others go through the pain I'm subjecting myself to, okay that sounds cruel, but at least it makes me feel better! You did a great job though, I'm looking forward to seeing more simulation stuff (and I would unironically watch 2h of this)

  • @sequelz
    @sequelz 2 ปีที่แล้ว

    Never saw you before, I'm 4 minutes into the video, already subscribed. Keep up the good work man ✌️

  • @lens3973
    @lens3973 3 ปีที่แล้ว +72

    Your style of comedy is amazing. Time to binge yet another creator's entire existence in just a few days.

    • @moonshot3159
      @moonshot3159 ปีที่แล้ว +3

      nah the kid is pretty cringe i'm glad i'm using sponsorblock to skip his fillers

    • @Lin_The_Cat_
      @Lin_The_Cat_ ปีที่แล้ว +1

      @@moonshot3159 ironic, 'cause calling people cringe for doing what they love and sharing it with others is pretty cringe if you ask me.

    • @moonshot3159
      @moonshot3159 ปีที่แล้ว

      @@Lin_The_Cat_ what you just said has earned you a ticket to cringetown.

  • @spde
    @spde 2 ปีที่แล้ว

    Your videos are SO funny!! You capture all the frustration I am feeling but make me laugh while watching 😁💀👍

  • @antoinecantin1780
    @antoinecantin1780 3 ปีที่แล้ว +11

    As a fellow sleep deprived math enthusiast and programmer who also likes to inflict pain upon himself with impossible projects; this video and your channel as a whole is great. Thank you "Inspecto" :)

  • @ankurage
    @ankurage 2 ปีที่แล้ว +1

    It looks like the sphere is trying hard to contain all the heat it gained from colliding with the walls

  • @jhdk356
    @jhdk356 3 ปีที่แล้ว +18

    Friction and dampening, my friend, that is the key to stabilizing. There are multiple different kinds, and often they are small enough to be dismissed. But whether it is air resistance or the springiness being dampened by the rubber converting motion into heat, or whatever, it is usually some variation of a force (/acceleration) in the opposite direction of the velocity, and is some proportion of the velocity or the velocity squared. So it will always attempt to counter the velocity, and bringing the system towards a stop (and gravity in this case keeps adding to the motion of the system). And since the velocity becomes slower and slower, the friction/dampening proportional to the velocity becomes lower and lower, thereby making the slowdown exponentially decreasing (sort of asymptomatic towards stand still).

  • @antoslv3913
    @antoslv3913 ปีที่แล้ว +1

    when a triangle decrease in size, the amount of force that it gets gets lower, and the points touch each other... is that why everything colapse ?

  • @deathworld5253
    @deathworld5253 3 ปีที่แล้ว +10

    6:45 - it's not the accuracy of explicit methods that's bad - it's instability. You raise your dt too high - you get an unstable system. And Runge-Kutta is excplicit too, so you'll inevitably will bump into problems with stability when you crank certain numbers too high or too low. Also, if your spring constant is very high - it's better in terms of calculation to implement them not as springs, but as a rigid rods. Also, you can add some dampening to your system to "vent" some instabilities that accumulate over time. I'm basically trying to accurately simulate problems like that (inflatable shells dynamics) and it's a living hell (But i'm going to use FEA since I don't need any real-time simulation).

    • @johnsherfey3675
      @johnsherfey3675 3 ปีที่แล้ว

      Basically you're avoiding at some level rounding errors that can occure.

    • @TheRainHarvester
      @TheRainHarvester 2 ปีที่แล้ว +1

      @@johnsherfey3675 it's not just rounding. But he could use double floats.
      Sometimes it's the approach and departure i describe in my micro gravity simulation.

  • @TroiMax
    @TroiMax 2 ปีที่แล้ว

    Thank you. You just took all my motivation learning to code.

  • @araghon007
    @araghon007 3 ปีที่แล้ว +11

    Ah yes, C# and OpenGL, I regretted doing that every single time, yet I still keep doing it

  • @hooeezit
    @hooeezit 2 ปีที่แล้ว

    Excellent sense of humor. Keep it up, buddy!

  • @olivander5171
    @olivander5171 3 ปีที่แล้ว +5

    i'd also enjoy longer videos on stuff like this

  • @hikari1690
    @hikari1690 2 ปีที่แล้ว +1

    Your code is so good it simulated material durability 🤣.
    In all honesty that's actually fantastic

  • @rahulpant9807
    @rahulpant9807 3 ปีที่แล้ว +6

    nice video gonkee. I studied 1984 in high school as well, not as my physics book though haha. keep it up

    • @chunji2321
      @chunji2321 3 ปีที่แล้ว +2

      Wow what a coincidence I also studied 1984 in highschool

    • @cardscook7721
      @cardscook7721 3 ปีที่แล้ว +2

      Wow! Same here. What a small world.

    • @JordanChung
      @JordanChung 3 ปีที่แล้ว +2

      @@cardscook7721 No way! I too studied 1984 at high school.

    • @theanonymousknight00
      @theanonymousknight00 3 ปีที่แล้ว +6

      @@JordanChung Bruh at this point these comments are looking like those scams in crypto videos "I too traded with mrs laura". lol🤣

  • @cedricsoares8277
    @cedricsoares8277 2 ปีที่แล้ว

    Good job! All you are missing is surface tension, a surface tangent force between vertices to distribute them homogeneous, in these case a spring like force pointing from vertice to its neighboring vertice on the mesh.

  • @oddmerlin9797
    @oddmerlin9797 3 ปีที่แล้ว +11

    ah yes, the reaction to the mathematics of collision, i know that one from experience

  • @thommekm
    @thommekm 2 ปีที่แล้ว +1

    8:54 I have an idea was is going on: could it be that the precision of your coordinates is getting worse the more your object moves away from the initial point?
    I remember watching a guy developing a fps engine and he had the same problem, that when he walked around in the world at some point the objects were getting "wobbly".. then he realized that the better approach is, freezing the player character at 0,0,0 and just moving the world around him. It's not solving your problem at all (unless your blob is THE central object) but could be an explanation..

  • @eduardojreis
    @eduardojreis 3 ปีที่แล้ว +4

    7:30 - I wish I had another like button to press here.

  • @tighemcasey7589
    @tighemcasey7589 ปีที่แล้ว +1

    When you have the issue of the mass exploding, it is likely because the spring mass system of the ball is a stiff system, although RK4 will increase the accuracy of the system (thus making it harder to explode) we can reduce the dependence on the systems spectral radius by using an implicit method. Backward Euler is very simple, but will work better than even RK4 on a stiff equation. There are many higher order implicit methods for differential equations if that is what is desired as well.

    • @tighemcasey7589
      @tighemcasey7589 ปีที่แล้ว +1

      I should also note you may need to increase the damping of the springs if resonance is the problem

  • @pizzaguy_
    @pizzaguy_ 3 ปีที่แล้ว +8

    "Okay i don't know how to make any of these but im sure ill figure it out."
    - Every programmer ever

  • @happyface8357
    @happyface8357 ปีที่แล้ว

    awesome and entertaining video man! hope you the best

  • @fredg8328
    @fredg8328 3 ปีที่แล้ว +4

    2:37 Fun fact. you can turn a quadritateral into 2 triangles with a simple line.

    • @temptedtrevor8498
      @temptedtrevor8498 3 ปีที่แล้ว +1

      Then each triangle wouldn't be equilateral though.

  • @subject2749
    @subject2749 2 ปีที่แล้ว +2

    8:28 the way the ball moves makes me feel incredibly uncomfortable no idea why

  • @toothlessblue
    @toothlessblue 3 ปีที่แล้ว +6

    One downside to the ico sphere, you don't get fine control over the resolution of it, if you want to increase the number of vertices, you have to subdivide it. Whereas UV and square spheres can have X by Y number of vertices, which is better for things like spherical terrain.

  • @1234567895182
    @1234567895182 2 ปีที่แล้ว

    Dude what you did is amazing. Especially knowing what you know in the amount of time you did it in. This is really impressive! The most I can do is draw a square. Actually, I can't even do that anymore because I forgot all my high school Java. Keep it up! You will be big brain one day! (youre already big brain tho

  • @augustvctjuh8423
    @augustvctjuh8423 3 ปีที่แล้ว +28

    I once made a cloth simulator (spring-mass system) and it had similar instability with ramping oscillation. It became a lot more stable when I introduced some sort of fake friction (just multiplied the velocity of each point by 0.99 every time step).

    • @FunnyFavor
      @FunnyFavor 3 ปีที่แล้ว

      Ew, that's a horrible way to do it

    • @augustvctjuh8423
      @augustvctjuh8423 3 ปีที่แล้ว +5

      ​@@FunnyFavor
      I'm not saying he should do this exactly in his project, it's still insightful information though.
      And for my project, it was perfect.

    • @official-obama
      @official-obama 3 ปีที่แล้ว

      @@FunnyFavor i would do that

    • @rdawo6408
      @rdawo6408 2 ปีที่แล้ว

      Can we post the result of your cloth simulator? 🤩

  • @frogman1
    @frogman1 2 ปีที่แล้ว

    oh my god. youre the guy that did the awesome godot water shader tutorial. cool channel!!

  • @guffs5270
    @guffs5270 2 ปีที่แล้ว +3

    now do it IN SCRATCH

  • @thisiskret
    @thisiskret 2 ปีที่แล้ว +1

    A combo of two people I never thought I'd see
    Dani and Dapz
    Dapzi

  • @AlexandreMercierAubin
    @AlexandreMercierAubin 3 ปีที่แล้ว +6

    You might want to use implicit methods. The common technique in Physics-Based animations is Backward Euler. This would be much more stable. If you really want to keep using explicit methods, make sure your time step is low enough and maybe add some damping. David Levin from UoT has uploaded superb videos for course on his youtube account. You should be able to learn everything you need to implement the other parts of your engine. PBD might have been a nice alternative way to make everything fit seamlessly in the same simulator, but I have personally made it work with FEM.

    • @LucaBl
      @LucaBl 2 ปีที่แล้ว

      Why would that be more stable?

  • @spencerpoole3959
    @spencerpoole3959 ปีที่แล้ว

    awesome video!!! Maybe to fix the ball you can add some sort of communication between adjacent points so that the small oscilations dont get out of hand?

  • @Pigster700
    @Pigster700 ปีที่แล้ว +4

    Now do it IN scratch

  • @NotoriousPyro
    @NotoriousPyro 2 ปีที่แล้ว

    Oh man I laughed so much at this video. I love your sense of humour. Subbed.

  • @lumps17
    @lumps17 3 ปีที่แล้ว +6

    I just completed a raytracer for a class, and the file that calculated intersections and collisions ended up around 900 lines long. I now have PTSD flashbacks whenever someone mentions collision 😭

  • @Jayprosunk
    @Jayprosunk 2 ปีที่แล้ว +1

    You should code an entire physics engine in scratch

  • @karenwright3618
    @karenwright3618 ปีที่แล้ว +5

    Gonkee: *Makes physics simulation and talks about it.*
    Also Gonkee: You know what, let's secretly rickroll the viewers!

  • @fatalinsomn1a182
    @fatalinsomn1a182 ปีที่แล้ว

    You could fix the ball by clamping the values so the points cant move past the center of the ball. You can calculate the center by averaging the position of several points for more accuracy.
    You can also clamp forces in other ways. In real life, this is like heat and friction losses. Most things dont perfectly transfer or transform energy.
    You can clamp the max spring length and cap the forces a little bit. You can use the length multiplied by a small constant to make the effect gradual, also forcibly clamping the positions of points to be on the right side of center, basically physical normal mapping, can all work together to make an object feel more solid and not gain energy incorrectly. So it feels solid, heavy, and realistic, and absorbs energy sometimes.

  • @miguelbaltazar7606
    @miguelbaltazar7606 3 ปีที่แล้ว +7

    1:59 yep I got rickrolled

  • @Canthev
    @Canthev 2 ปีที่แล้ว

    Looks like you could add a "damping" term to your Mass-Spring modeling for the tensile forces. It's a fairly common system. Instead of being a Mass-Spring system, it becomes a Mass-Spring-Damper system (sometimes referred to as MSD). The damping term creates a force opposing the direction of travel. The damping term is c*x_dot (damping coefficient [constant] * velocity of mass). So as the mass (vertice in this case) begins traveling at a high speed, a large oppose force (created by the damping term) begins to get generated, which will cause the mass to decelerate. If you implement a damping term to your physics engine, you might find that you no longer have the ball shaking itself to death! I might try and do this for you if I have some time to take a look at the code. Cool video regardless! :)

  • @Drakonus_
    @Drakonus_ 2 ปีที่แล้ว +2

    "I have no redeeming qualities."
    ~The guy who has the skills to create an entire physics engine from scratch

  • @mzg147
    @mzg147 3 ปีที่แล้ว

    Just... amazing! Thanks for your content.

  • @jayeifler8812
    @jayeifler8812 ปีที่แล้ว

    Be a badass and program your own tcad and spice software. You could make it big. There's already some open source. You just want to have a complete tcad and/or spice together that's competitive with the commercial stuff, then you make a big break through in universities by getting lots of grad students, postdocs to use the stuff since they can program their own models. Like Oliphant did numpy. You'd also wan to make sure to have thermals sims possible too. Separately a matching electromagnetic wave simulator with its own spice and thermal sims is a whole second project. Not sure it's yet possible to have combined electromagnetic wave studies and tcad level modeling for semiconductors.

  • @ijcurtis
    @ijcurtis ปีที่แล้ว

    Maybe try using fewer triangles to construct the icosphere? I would also include some dissipative forces in addition to Hooke forces if you haven't already.

  • @RikMaxSpeed
    @RikMaxSpeed ปีที่แล้ว

    Great video and learning exercise. I’d recommend implementing a vector class so you can reduce your code by a factor of three!

  • @abadhaiku
    @abadhaiku ปีที่แล้ว

    What's great about programming in Java is that you can use ASM to inject code wherever you want in any part of the program. Who needs to write from scratch when you can just get admin access and edit stuff?

  • @Tanicorn
    @Tanicorn 2 ปีที่แล้ว

    Oh wow, you made the github repo accessible thank you so much...
    I can't wait to code this myself

  • @Gabemeister1201
    @Gabemeister1201 3 ปีที่แล้ว

    I appreciate the use of the 'Winter is Coming' theme for vs

  • @tchakenamea8944
    @tchakenamea8944 3 ปีที่แล้ว

    The strings between points not lose energer through time maybe that's the reason why your ball begin being "shaky". Every bounces add more energy to your bounding system, and the ball can explode due to too much accumulation. The string are like vibrating, go look forward energy dissipation, like dampeners inside a vehicule. Great Job with programming !

  • @godnyx117
    @godnyx117 ปีที่แล้ว

    I'm in the 3:36 mark and I'm lucking my ass off! You have talent my friend!

  • @Canaldenono
    @Canaldenono 2 ปีที่แล้ว

    Physics mayor here, you basically implemented a kind of not very stable bubble, not a boucy ball! The ball may be stimulated more accurately by defining a 3d mesh (as if it was a cristal lattice of some sort even if it's not) and adding "spring forces" to each one, and not only with the first neighboring points, but to the 2nds and 3ds also. I would love to see the behaviour then! I loved the video, keep up the good work!

  • @brainther
    @brainther 2 ปีที่แล้ว

    this is the first video I see of yours, and I really love the content, you def deserve a sub

  • @varunahlawat9013
    @varunahlawat9013 2 ปีที่แล้ว

    OMG, I've just started coding two months ago. First time seeing something like this! Being a physics lover, I want to turn my physics knowledge into something like this.
    I subscribed to learn moreee, can't waittttttttttttttttt....

  • @HyperFocusMarshmallow
    @HyperFocusMarshmallow 2 ปีที่แล้ว

    I love how you try but then it turns out to be hard. That’s the only way to learn your blind spots. Hope you can improve it in the future!