An In-Depth look at Lerp, Smoothstep, and Shaping Functions

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • Exploring some common math that game developers use, let's look at linear interpolation and apply it to everything.
    🛒 Recommended books (on Amazon): www.amazon.com...
    ❤️ Support me on Patreon: / simondevyt
    🌍 My Gamedev Courses: simondev.teach...
    Disclaimer: Commission is earned from qualifying purchases on Amazon links.
    Follow me on:
    Twitter: / iced_coffee_dev
    Instagram: / beer_and_code
    In this video, I cover lerp, also known as mix in GLSL, a common mathematical function used in game dev. It's extremely versatile, and we'll go through basic uses, as well as some problems and how to overcome them.
    Some easing functions to try out:
    easings.net/
    iquilezles.org...

ความคิดเห็น • 222

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

    Typo at the end! Should be b^(n+m) = b^n * b^m
    Btw, support me for more videos:
    GLSL Course: simondev.teachable.com/p/glsl-shaders-from-scratch
    Patreon: www.patreon.com/simondevyt

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

    Holy crap!
    A long time ago, I was writing a multiplayer top-down shooter and I ran into a weird issue where the camera would start jittering like crazy, some kind of de-sync between the client and server. I never figured it out and just lost hope in the project, abandoning it.
    Fast forward *15 years* and at the end of a video about interpolation, there's a quick side-note about a common mistake when interpolating positions. And, if memory serves, that is *exactly* what I did with the camera.
    ...Holy crap..!

    • @5hirtandtieler
      @5hirtandtieler 2 ปีที่แล้ว +49

      Time to pay a visit to your closet/storage unit and dust off the old hard drives....

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

      What is the mistake?

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

      You're saying it jittered, so it's probably not the mistake mentioned here. (If you even consider it a mistake - it's so close to being perfect that you might as well use that solution).
      But if I were to guess, it's possible that you accidentally let t be larger than 1 - making the camera overshoot its target. If frame rates were low enough, you'd get jitters as the camera moves back and forth.

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

      Hey man, if your game is fun, I think you should just resume working on it. Don't bother with visual updates. The market needs more passion projects and fun games.

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

      @@commenturthegreat2915 They said the stutter is caused by a desync between server and client. If the server is running interpolation at a fixed timestep and the client is doing it based on framerate, then yes actually this would be precisely the type of thing that would cause desyncs in position.

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

    Thanks, Simon. I'm lerping as a programmer but smoothing and shaping my path.

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

    I didn't check the math exactly but the last example when you are following the target, you are effectively solving a differential equation. The initial fix by multiplying by timestep should be forward Euler method. Using the exponential is an exact solution to the differential equation, hence the frame rate independence. However, it is exact solution only if the target is stationary(maybe also in the case of linear movement). Therefore it is still not frame rate independent but the error is much much lower.

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

    There is a mistake at 8:07 IG b^(m+n ) = b^m * b^n not b^(m+n) = b^m + b^n.

  • @afriendlyfox
    @afriendlyfox หลายเดือนก่อน

    I was lerping to change model heading, and the speed of the rotation was behaving differently in Unity editor and in build, and what you are talking about in the end was the exact problem I found.. and yes, I fed the delta time into the lerp to "solve" it. Thank you so much for the proper solution!

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

    Every time I go to write I a comment you're ahead of me explaining what I know from intuition, but way better than I could. Then adding to that something I don't know.
    brb gonna bing your videos.

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

      Hah, happy you're getting value from them!

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

    Wow, I don't think I've seen such a useful video before, and it only was released a week or two ago. Major props, thanks for sharing

  • @ironcommando2
    @ironcommando2 6 หลายเดือนก่อน

    I gotta thank you a lot especially for that last one. My camera was lerping weirdly on different frame rates and that solved my problem!

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

    Good to see you making videos again! I always learn something.

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

    1:13 Using this in conjunction with ‘B*t + A*(1-t)’ was an idea I never heard before and will be SO MUCH more useful than having to go into desmos to hand craft functions whenever I need interpolation, so thank you for all this!
    I know this was probably the simplest concept for others, but I work in a sim tool that doesn’t offer interpolation functions and I only really need them when making nice animations. But this is so much cleaner than reimplementing complex functions...

  • @buzbuz33-99
    @buzbuz33-99 2 ปีที่แล้ว +2

    Amazing stuff. I've done all these kinds of things without LERP (e.g., moving objects, color transitions, camera tracking). So it will be interesting to see how I use these commands to improve my programs.

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

    I've been doing smooth lerping as shown at the end wrong all this time! I did the exact same as the same as the second example, slapping on delta time. I was never satisfied with how it looked with low framerates as it gets jittery, so I tended to add some additional checks to make it not freak out.

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

    Oh my god, learning the right way to lerp positions independently of framerate IS a must and I never thought of it... Totally required for online games where position matters.

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

    This is gold. Thank you for all the effort you put into this beautiful video

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

    I will appreciate more math videos like this. thanks

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

    lost me at the end lol but very good video on some game maths fundementals. Nice refresher after not having dabbled in stuff like shaders in a while

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

    Loved this so much Simon! Thanks for the video 🙆🏻‍♂️

  • @robbillington1603
    @robbillington1603 หลายเดือนก่อน

    Damn Bob Belcher is also a math nerd???? Such a good video

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

    Fantastic video - thank you

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

    Super cool video. Love to see more of those math videos :)

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

    omg definitely use quaternions to interpolate between two random rotations ;D

  • @while.coyote
    @while.coyote ปีที่แล้ว +1

    I love this, thanks

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

    I only subbed bc of that cheeky little gag you did.

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

      but forreal, this is very useful if I eventually finish my ideas for music production plugins.

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

      😀

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

    Is there a course that teaches you the various ways to apply this? I’ve been having very limited success in experimenting by myself and I think I need, like, a legit teacher to help me step by step

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

      Yeah, I have a shader course that uses lerp (mix in glsl) extensively.

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

    Thanks Bob from the hit show Bob's Burgers

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

    very very cool! thank you!

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

    Here's a simpler smooth step function: f(t) = 3t²-2t³ = t²(3-2t). I'm not sure if it gives better or worse results

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

      It's actually the same. If you plug the equations A = t² and B = 1 - (1 - t)² into the lerp equation B*t + A*(1 - t) and simplify you get 3t² - 2t³
      (1 - (1 - t)²)*t + t²*(1 - t)
      (1 - (1 - 2t + t²))*t + t²*(1 - t)
      (1 - 1 + 2t - t²)*t + t²*(1 - t)
      (2t - t²)*t + t²*(1 - t)
      2t² - t³ + t² - t³
      3t² - 2t³

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

      @@clif2craf273 I know. Here's my way to get it:
      f(t)=lerp(1-(1-t²), (1-(1-t)², t)=
      =1-lerp((1-t)(1+t), (1-t)(1-t), t)=
      =1-(1-t)lerp(1+t, 1-t, t)=
      =1-(1-t)((1+t)(1-t)+(1-t)t)=
      =1-(1-t)²(1+2t)=
      =1-(1-t)²(1+2t+t²)-(1-t)²t²=
      =1-(1-t)²(1+t)²-(1-t)²t²=
      =1-(1-t²-t+t²)(1-t²+t-t²)=
      =1-(1-t)(1+t-2t²)=
      =1-(1-3t²+2t³)=
      =3t²-2t³
      I just decided to see how fast someone replies with that

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

      @@clif2craf273 It may give different results due to precision errors

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

    note to self: slerp = spherical linear interpolation

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

    Very nice

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

    Very good video, keep it up

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

    instant subscribe!

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

    After plotting a few of the smoothstep family of functions, it seems like it gets steeper and steeper in the middle. Does it converge towards the discontinuous step function, or towards a "smoothest" step function ?
    My intuition would be the former, since the nth derivative of S_n is made to be zero at x=0 and x=1 on purpose, the taylor series should be 0 + O(x^n) and 1 + O(x^n) respectively, and thus should converge to 0 and 1, with a discontinuity in the middle. Maybe the function isn't analytical, but all smoothstep functions are polynomials and therefore analytical, so I don't think that's possible...

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

    You are a god

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

    I really love math hence why i Study math, but i hate programming outside of solving real problems. Its nice to see a use of math in things i take for granted.

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

    there's a typo at the triangle function lol

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

    I really have to ask. Where do you learn this stuff and what resources do you use? I am not just referring to the concepts since i was familiar with most of them. I mean their practical applications and real examples

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

      Mostly practice and experimenting by doing small projects and larger ones

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

      @@valovanonym i understand practice is key, but I am asking where did he learn this because you can only practice something after you learn it

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

    0:28 the t shall be [0..1] and A and B shall be constant but in 7:15 it is a wrong usage of lerp because of two things 1/ using delta time x movement time (instead of t = [0..1]) can be > 1, and 2/ because the new value of A is used back in the next iteration, so this will never converge i.e. for camera transform.position = lerp(transform.position, traget_position, dt * K) your camera never halt moving since, let suppose dt * K is constant 0.5, and initial distance is 1 unit, you'll move of 0.5 at initial step then moving of 0.5 of the 0.5 for the second iteration, then 0.5 of 0.5*0.5 for the third etc ...

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

      We'll get down to Planck length eventually, it's anyone's guess at that point :)

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

      @@apasserby9183 yep definitely not the good algorithm for modeling the Universe lol

  • @HammaGaming
    @HammaGaming 6 หลายเดือนก่อน

    I Really need Help ! I have a problem that the lerp speed is framerate depended even when multiplying by deltatime or 1 - Mathf.Pow(rotationSpeed, Time.deltaTime). let's say the game run at 100 fps the lerping speed will be slower than when it run at 30 or 20 fps.
    This is the code in unity C# in update method:
    Angle = Mathf.LerpAngle(transform.eulerAngles.y, targetAngle, 1 - Mathf.Pow(rotationSpeed, Time.deltaTime));

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

    React Fiber I'm coming for you!

  • @baptiste-genest
    @baptiste-genest ปีที่แล้ว +1

    great video but b^(n+n) = b^n + b^m???

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

      Yeah, I flubbed that part, don't remind me heh. Fix is in the pinned comment.

    • @baptiste-genest
      @baptiste-genest ปีที่แล้ว +1

      @@simondev758 oops sorry I didn't see the fix, forget what I said, shit happens, and only remember that I manifested how great I think your work is!

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

    Lerp, haha

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

    Was following everything until the last part. What????

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

      2x applying lerp at 60 fps shall give the same result as 1x applying lerp at 30 fps, so you get the same result from t = 0s to t = 1/30s
      He therefore said lerp(a,b,t) shall be lerp(a,lerp(a,b,t/2),t/2), and the pow functions ensures that.

  • @leandrotarsia7212
    @leandrotarsia7212 8 หลายเดือนก่อน

    I feel dizzy.

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

    DO NOT BLEND COLORS LIKE THIS! It causes wacky issues because of logarithmic color

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

    i like the part where he said "It's lerping time!" and lerped all over the place

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

      Man, I really lost an opportunity to actually do that

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

      @@simondev758 The fact that you didn't do it makes the joke funnier.

    • @user-pr6ed3ri2k
      @user-pr6ed3ri2k ปีที่แล้ว

      ​@@simondev75842thliker

    • @MAGNETO-i1i
      @MAGNETO-i1i ปีที่แล้ว +6

      Go Go Lerping Rangers!!

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

    Great video, thank you!

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

    Your smooth voice and professional animation and videos design gives your videos such nice aesthetics! Also love the knowledge you share with us

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

    Sorry... shouldn't it be b^m * b^n = b^(m+n). Is it different if the numbers are strictly between 1 and 0?

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

      I wanted to write the same thing. I think this is a typo

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

      Dammit

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

      Even worse, this was correct in my draft, haha

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

      @@simondev758 it's the consequence of doing too much math haha
      I just made a matrix multiplication function in JS last week where I added instead of multiplied the elements, so it'll be the first thing I look for a while 😂

  • @magic-window
    @magic-window 2 ปีที่แล้ว +19

    That's an effective lesson, explaining all these concepts, functions, and implementations in such short time.

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

    Nice linear/log zoom example! I was just staring at a linear fade in and thinking it didn't look good. I'll have to give log a try

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

    This video needs to be waaayyy longer. I want more!

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

      I'd say the length is very good. I feel like I now know what to google when I need to implement it and know the most common pitfalls. I'd just forget most of it if more info were crammed in the video.
      I'm sure there are more in depth videos on interpolation functions tho.

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

    Hey, so some people (like me) might be calculating their lerp rate as t = K * (targetFrameRate / frameRate) instead of t = muchLargerConstant * frameTime {i.e. t = .35 * (60 / 240) instead of t = 21 * (1 / 240); this is if the result is supposed to be equally large, t = .0875 in both cases} bc they wanted to be able to write constants (K values) that were equal to the actual used lerp rate at a target frame rate, meaning a lerp rate between 0 and 1. If you use a K value from 0-1 in the second equation, your t value will be very low and cause slow lerping, thus you have to use a K value that is (targetFrameRate) times as large as the first equation (21 = .35 * 60) to get the same result. Basically, if you are ok with small lerp rates, then the second equation works fine with K being a 0-1 value, and the use of the equation presented in the video gives similar results. Using my method, however, means that your constants will not work the same way in the new frame rate independent lerp function. And if you, like me, instead of refiguring many different lerp constants, want to use the same constants to get the same result except truly frame independent, then you can use this method. After some fiddling with math, I found that you can add an extra constant out front of the (new) equation so that it becomes:
    t = A(1.0 - pow(K, frameTime)),
    where: A = K / (1.0 - pow(K, (1 / targetFrameRate)))
    It probably goes without saying, but this has the same effect if you were previously using something like: t = targetFrameRate * K * frameTime, as that is the same as my original equation.
    There is probably a shorter version of calculating A, but I didn't bother trying to condense it.
    A stands for Adjust, as it adjusts the result of the new function to be identical to the result of K * (targetFrameRate / frameRate) at a given targetFrameRate and all subsequent rates for different real frame rates to be much closer to the original function as well, allowing you to use the same K value used while utilizing t = K * (targetFrameRate / frameRate) (Note: There is nothing wrong with the equations in the video, they just give small lerp values that you might be required to adjust later since you can't use a K value greater than 1 in the new equation). The constant A only needs to be calculated once upon creation of the object that uses A (assuming K is indeed a constant). In summary, this provides a way for t values from the new equation to be close to the old equation using the same k values. I hope this helps anyone looking to implement this function in an already largely completed version of their project! And here is a Desmos graph I set up to help understand why this might be useful:
    www.desmos.com/calculator/sylkom3bze
    Try getting rid of A on the purple line and f on the blue line. That illustrates the exact way the original equations were portrayed in the video.

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

      Awesome, yeah that was one problem with the new equation, is that it doesn't map easily to the old values without some work. And I didn't do the work heh

  • @doxed64
    @doxed64 9 หลายเดือนก่อน +7

    This is exactly what I needed for my game. Camera Log Zoom and Frame Rate independent tracking for aiming. Thank you so much, Simon! Subscribed.

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

    I've experienced 2 of the issues mentioned with deltaTime lerping and the camera zoom lerping problem. I found ways around both at the time but this video was very insightful and i've made some notes for these in the future as i'm sure i'll run into them again. I knew how lerp worked but i was always curious about smoothstep, it was funny cuz i've experimented with lerping between lerps so was a suprise that i was on the right track just didn't think of the sqrt. Great video Thanks!

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

    it's like all the fun parts of cs course without the boring parts

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

    Crazy good videos thank you!

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

    Interesting stuff. My favorite functions in Unity game development always has been lerp and slerp because they are easy to use and extremely useful in many situations. Also I love their names

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

    Rewriting my old code I guess .

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

    Thank you Simon! I'm studying CS and this is amazingly useful.

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

    amazing video,
    you should leave a little more time at the end of the video, so the recommended videos appear there. Currently the explanation of method #3 get interrupted for being at the end of the video

  • @cicada.and.pomegranate
    @cicada.and.pomegranate ปีที่แล้ว +2

    I love the part where he said "it's lerping time" and lerped all over everyone.

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

    My only issue with lerp is not calling it lint... Then again, without lerp, we wouldn't have "slerp" lol

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

    I didn't know I needed this video until now, thanks!

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

    on the 3rd method, frame independent lerp thing,
    its ilke K = 1 - pow ( K , frameTime)
    we're using the variable K when declaring it is odd.
    shouldn't it be pow(constant , frameTime) ?

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

      Oops, yeah, it's more like
      K = some_constant
      K = 1 - pow(K, frametime)
      etc..

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

    Loved the video. Disliked the end. The thumbnails covered the code, didn't have time to read it or think about it. Thanks for the video!

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

    I'm currently working on a game that has some events that sometimes causes a spike in the frame time, if I happened to be moving the camera in a specific way during those events the camera starts to freak out shaking all over the place. I ironed out some time consuming events to minimize the problemas but never understood why the camera of all things was suffering from the fps drops... until now

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

    At the start, why did you visualize "A plus varying amounts of B"? You said "half A plus half B" but animated "A plus change". It's been 20 seconds and the video already doesn't match your script. This is math, these things are important!
    Thank you for making the video nonetheless.

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

    One content, two languages. What I have now written may have a perfect mirror in another language.!!!!!!!!!!! Hack in the brainlll

  • @erksp7961
    @erksp7961 5 หลายเดือนก่อน +1

    Thank you! This helps me _understand_ the functions. Cheers!

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

    Fuck I forgot about slerp no wonder my normals and tangents were bad when I wrote my Terrain generation system… Thanks a lot

  • @RDD87z
    @RDD87z 9 หลายเดือนก่อน +1

    super helpful! thank you so much.

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

    Lerping is kinda giving me Bezier curve vibes

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

      I mean, bezier curves are just repeated lerps heh

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

    Simon please make this a poster and i will buy it 😁👍

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

    Bob Belcher's computer genius brother's name is Simon.

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

    Watched this a second time, realized already had given a thumbs up.

  • @Rafael-rm8ex
    @Rafael-rm8ex ปีที่แล้ว +2

    this is how much a guy can be genious...

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

      Not a genius, just been in the industry a few years heh

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

    Great video

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

    Wait why is Delta t not enough for syncing position and lerping?
    P1 += v*dt
    P2 += v*dt
    P1 and p2 are time-synced, just ad the lerped values are. What am I missing??

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

      The two scenes shown in the video are running at different frame-rates. Also, it is not simply using a velocity to calculate a new position, but rather lerping towards a target to create a "follower" behavior. That means the actual speed of the object being simulated depends on the distance between the object and the target on any given frame.
      Since the bottom scene runs twice as fast as the top scene, while the top scene is still calculating the new position, the bottom scene has already moved the object closer to the target meaning the speed will actually be slower on the next frame. So if we call the distance covered in one frame by the object on the top "d", then the object on the bottom covers a distance 0.5 * d on the first frame, and then a distance _smaller_ than 0.5 * d on the second frame, meaning the overall distance covered by the object on the bottom is not d.

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

      @UCSEjq8o06sqfuJ10jK26jYw
      "The video is effectively saying that higher frame rates are more accurate"
      When we aim to achieve _frame-rate independence_ in our games, no frame rate should be any more accurate than any other. The output of the system should only depend on the time, not on how many frames it takes to get there.
      "Won't the delta t's just cancel out the difference?"
      Maybe my previous comment wasn't very clear. If we have two games running, one with a frame time dt and another with frame time 0.5 * dt, then the second can calculate two frames in the time it takes the first to calculate one. Since the speed of the follower depends on the distance to its target, on the second frame it is closer, and therefore _slower._ The result is that it actually covers less distance than the game running with a lower frame rate in the same amount of time.

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

      @@APaleDot Hm... Still can't catch it right
      If the first instance is running with a dt1 = 10ms (100fps) and the other one runs dt2 = 20ms (50fps)
      After same amount of time both will be in same position as
      dt1*fps1 == dt2*fps2
      So both positions should be the same, just like the speed if acceleration also considers dt

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

      @@MrJloa
      They won't be in the same position because we're lerping, we're not moving with a constant speed.
      As shown in the video, lerping towards a target can be achieved by doing x' = x * (1 - dt) + y * dt, where x is the position of the follower and y is the position of the target.
      Then in the 20ms case, the final position after 20ms is x' = x * 0.98 + y * 0.02. Basically, 2% of the way towards y.
      In the 10ms case, we have to run the calculation twice. On the first frame we get x' = x * 0.99 + y * 0.01, and then the final position after 20ms is x'' = x' * 0.99 + y * 0.01.
      Substituting x' into that equation gives us x" = (x * 0.99 + y * 0.01) * 0.99 + y * 0.01, which is not 2% of the way towards y. If you do the math it's actually 1.99% towards y. It may seem like a small error, but with faster speeds and larger differences in frame time, it can make a difference.

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

    thanks for these videos.. these are pretty dope :D

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

    2:43 "A parabola..."
    *shows a bell curve*

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

    How do you generate the voice on these videos? It sound super real 👍

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

    Sadly... I slept at math, so thank you! 😂

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

    I wonder if the log function for zoom in zoom out should not be a sqrt function for natural view, because then your velocity with which you distance in or out is constant, as the area you cover increases with the sqr of the distance.

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

      Might be interesting to try

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

    very nice, i like it a lot. short and on topic.

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

    Ah yes, lerp. Lerv erction rerl pley

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

    smoothstep looks like a sigmoid

  • @rafaelbrustolin4687
    @rafaelbrustolin4687 7 หลายเดือนก่อน +1

    useful stuff i found here

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

    " an in-depth look " .... " we won't dive into the math " ... NullLogicException: " Statement B makes no sense after declaring A. " 😛
    ( it's a joke, but also kinda true real )

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

      Heh, I figured slerp's internal logic was out of the focus of the video 🙂

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

    I wish this video existed when I was getting to know all about these functions myself! Great video!

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

    very nice. thank you.

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

    Serious tidbits my man

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

    A bunch of awesome concepts in just enough detail, great video!

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

    Yeah, you did one thing wrong at the end. You slapped the end cards all over the final formula so only a small piece of it is visible from underneath.

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

      Yeah, didn't realize I did that heh, really wish there was a way to edit videos a bit after but eh

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

    Love IT, thank u

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

    This is really cool

  • @simtrip6452
    @simtrip6452 10 หลายเดือนก่อน +1

    I'm not sure if what happened at 7:47 was a genuine audio screwup or you faked out censoring the word "infuriating" but I love it

    • @simondev758
      @simondev758  10 หลายเดือนก่อน

      Oh weird, yeah that's totally something going wacky with the audio heh

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

    Thanks. That was really interesting and inspiring!

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

    Lerpa Derpa herpa doo

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

    Nice