Damping with delta-time

Just a quick tip on how to convert usual damping code to something framerate-independent.

Most of us have probably, at some point, written code resembling this:

// Perform velocity damping
velocity -= velocity * 0.01f;

… or probably the more correct:

// Per-second damping coefficient
float const D = 10.0f;

// Damp velocity according to timestep
velocity -= velocity * D * delta_time;

Yet this is not fully framerate-independent; results are slightly different at 30fps and 60fps, and more importantly, spikes in the framerate cause lots of weird artifacts, causing developers to attempt to fix the situation by clamping delta_time, which is not ideal.

The exponentiation method

Here is one way to fix it: assume that the code works correctly at 60 fps. This means that each frame, velocity is effectively multiplied by 1 - D / 60.

After one second, i.e. 60 frames, velocity has been multiplied by (1 - D / 60) ^ 60.

After two seconds, it has been multiplied by (1 - D / 60) ^ (60 * 2).

After N seconds, it has been multiplied by (1 - D / 60) ^ (60 * N).

So, there, we have a formula that tells us what happens after N seconds, and it’s a continuous function. We can therefore choose N as we like, and especially N = delta_time:

// Per-second damping coefficient
float const D = 10.0f;

// Damp velocity (framerate-independent)
velocity *= pow(1.f - D / 60.f, 60.f * delta_time);

Which can be conveniently rewritten as:

// Per-second damping coefficient
float const D = 10.0f;
// Exponentiation base for velocity damping
float const D2 = pow(1.f - D / 60.f, 60.f);

// Damp velocity (framerate-independent)
velocity *= pow(D2, delta_time);

Use with lerp

The same method can be adapted to uses of linear interpolation such as this one:

// Perform velocity damping
velocity = lerp(velocity, target_velocity, K * delta_time);

Which we replace with:

// Damp velocity (framerate-independent)
velocity = lerp(velocity, target_velocity,
                1.f - pow(1.f - K / 60.f, 60.f * delta_time));

Comments

1. b.stolk@gmail.com -- 2015-05-04 16:25

Alternatively, you could do the simple damping, and always use dt 1/120. For 60 fps you call it twice, for 30 fps you call it four times.

The results will have no difference due to floating point accuracy, as would the solution above.

2. JohnWilson -- 2017-10-10 08:28

It appears to manifest on the Unity gatherings over and over and again the right utilization of straight interjection for damping a value. You have a value, an, and you'd like the chance to easily move it towards another value b, so you choose to utilize straight introduction with some subjective rate r. In the event that you accomplish something like this in your variable rate refresh work. custom dissertation help | DissertationTime

3. Christina John -- 2017-10-11 16:02

I'm endeavoring to step by step lessen the speed of a question, utilizing a "damping" property. From that point onward, I need to move the question's position utilizing the speed. Visit here http://www.assignmentchamp.co.uk/

4. anonymous -- 2017-10-13 12:05

papas cupCakeria allow to his users free access you want play then guys here is a link http://papacookinggames.com .After just a single click you will be on papa cupCakeria .Thanks a lot

5. anonymous -- 2017-10-23 10:23

You have an esteem, an, and you'd like the opportunity to effortlessly move it towards another esteem essaychamp.co.uk b, so you use straight presentation with some subjective rate

6. anonymous -- 2017-11-08 10:32

If you are want to know about where all the program in windows 10 online then this is the best place http://allprogramswindows10.com to know about program in windows 10.

7. Hann Erv -- 2017-11-09 11:18

"Alternatively, you could do the simple damping, and always use dt 1/120. For buy an assignment online 60 fps you call it twice, for 30 fps you call it four times." Well it just worked for me, thanks mate!!

8. anonymous -- 2017-11-15 12:50

Great article. This is something I've been thinking for a while: one doesn't have the right to (or should not) write until one has read most of the literary canon. http://www.wewriteessay.co.uk/

9. assignmentinc -- 2017-11-20 11:04

This is really a great stuff for sharing. Keep it up. Thanks for sharing. https://www.assignmentinc.com

10. auditinghelp -- 2017-11-20 11:05

This is really a great stuff for sharing. Keep it up. Thanks for sharing. http://auditinghelp.com/

11. Kellyleona -- 2017-11-27 15:06

I realize that the school board discharges a particular AP Stats rehearse exam accessible for educators to provide for their understudies as training http://www.Aoneassignment.com. I am mentoring a few understudies for AP insights and might want to give them this training exam to set them up for the AP.

12. anonymous -- 2017-11-28 09:55

Hello everyone, was interesting to read your article. Usually im reading New York Times (it's here, if u want to check it out https://www.nytimes.com), but now i'll read your site too!

13. wilsonlarrie1 -- 2017-11-29 05:45

Hi buddy, your blog' s design is simple and clean and i like it. <a href="https://www.psychologyassignments.com/">Psychology Homework Help</a> Your blog posts about Online writing Help are superb. Please keep them coming. Greets!

14. anonymous -- 2017-11-29 06:14

It seems to show on the Unity social affairs again and again and again the correct usage of straight interposition for damping an esteem. You have an esteem, an, and you'd like the opportunity to effortlessly move it towards another esteem b, so you use straight presentation with some subjective rater. If you fulfill something like this in your variable rate revive work. http://www.essaycorp.co.uk/

15. anonymous -- 2017-12-02 06:44

Nice post because - A quick aside for those not familiar with Unity: Each script has three different update functions that can be called. Update is called as you would expect, and LateUpdate is a version that's called well, later on in the frame. Both of these should use the global (yikes) Time.deltaTime to access the variable frame ... http://www.theacademicpapers.co.uk/coursework-writing-service.php

16. Danny -- 2017-12-03 20:18

I’ve read the topic with great interest and definitely will stick your blog routinely for other great posts. Thank you for sharing this valuable and great article. https://custompaperswritinghelp.com/human-resource-management-topics/

17. Do my Assignment -- 2017-12-19 09:06

I understand that the school board releases a specific AP Stats practice exam open for teachers to accommodate their understudies as preparing http://www.assignmentkeen.com/write-my-assignment. I am coaching a couple of understudies for AP bits of knowledge and should need to give them this preparation exam to set them up for the AP.

18. Write my Research Paper -- 2017-12-19 12:20

It appears to appear on the Unity get-togethers over and over and again the right utilization of straight intervention for damping a regard. You have a regard, an, and you'd like the chance to easily move it towards another regard b, so you utilize straight introduction with some subjective rater. On the off chance that you satisfy something like this in your variable rate restore work http://www.researchpapertown.com/

19. Do my Assignment -- 2017-12-19 12:44

It appears to appear on the Unity parties over and over and again the right use of straight intervention for damping a regard. You have a regard, an, and you'd like the chance to easily move it towards another regard b, so you utilize straight introduction with some subjective rater. On the off chance that you satisfy something like this in your variable rate restore work. http://www.assignmentland.com/write-my-assignment

20. Martin -- 2018-01-15 12:01

You have made a great tutorial which i like reading. I must say you have made a great effort in making this post. Purchase grass protection mesh from http://groundreinforcementmesh.co.uk/

21. anonymous -- 2018-01-15 12:58

What a good post.There are very useful points shared in this post which practically makes it work. Practical points are very useful for us. Thanks for it. To get playground tiles Click here http://playgroundtilesuk.co.uk/

22. anonymous -- 2018-01-16 13:43

I appreciate this work amazing post for us I like it. https://TheCaseSolutions.net

23. anonymous -- 2018-01-24 09:04

Thank you for your work on the blog! You're doing a good job!

https://19216801.mobi/

24. Assignment For Myob -- 2018-01-25 11:37

I'm getting excited about this kind of beneficial information of your stuff in the future https://www.myobassignments.xyz/

25. anonymous -- 2018-01-26 10:51

This is awesome - <a href="http://www.pcmunkey.net/">get free psn codes</a>

26. anonymous -- 2018-01-27 10:42

This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this..

http://www.moviesjacket.com/blog/poe-dameron-costume/

27. anonymous -- 2018-01-27 12:02

This is an unbelievable rousing article. I am fundamentally satisfied with your great work. You put truly exceptionally lodging data...Amazing Work..! https://www.hjackets.com/

28. Java Assignments -- 2018-02-01 06:05

This site and the resources you provide is really nice keep it up. https://javaassignments.com/

29. anonymous -- 2018-02-05 08:07

I am very happy to read this. This is the kind of manual that needs to be given and not the random misinformation that’s at the other blogs. Appreciate your sharing this best post. https://www.essayjaguar.com/

30. Clark -- 2018-02-10 11:34

My first time to visit in the blog. In the blog is very interesting ans informative for me. Thanks for sharing in the information. http://www.customboxesco.co.uk/

31. Albert Thomas -- 2018-02-16 12:09

https://www.academicpaperwriter.com/ I am so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that's at the other blogs.

32. Eden Carter -- 2018-02-16 12:30

My friend recommended this blog and he was totally right keep up the good work https://www.casestudy.help

33. Stats Homework Help -- 2018-02-24 10:17

I'm getting excited about this kind of beneficial information of your stuff in the future https://statisticshelponline.xyz

34. anonymous -- 2018-02-27 11:49

really nice code in this article how to convert usual damping code to something framerate-independent explain is very nice thank u for sharing it is very useful to me.....

http://www.certvalue.com/iso-14001-certification-in-philippines/

35. anonymous -- 2018-03-01 03:29

I think this is a good article if you are an <a href="https://www.myessaywriter.net">essay writer</a> looking for an <a href="https://www.myessaywriter.net">essay writing service</a> or you want someone to <a href="https://www.myessaywriter.net">write my essay</a>.

36. anonymous -- 2018-03-02 15:39

This post inspired me to take concrete actions, thanks for creating it, it turned out to be very useful http://19216811-admin.com/192-168-0-1/ 192.168.O.1

37. david mitchel -- 2018-03-03 08:19

People also writing the blog on this topic but the points which you have shared has an incredible for me. I really appreciate this work reading physic studies.

https://www.doneessays.co.uk/

38. anonymous -- 2018-03-03 12:45

Whatsapp web is the latest web-based technology launched by Whatsapp web download developers to use this amazing application on your PC/ Laptop for free <a href="https://iwhatsappweb.co/">read more</a>

39. anonymous -- 2018-03-13 06:52

Those students and learner who are facing the problem in their physic studies so they must try to join this forum for getting daily updates on this subjects.

claim compensation for accident

40. anonymous -- 2018-03-13 10:29

How to get ISO certification is Saudi arabia is became easy with kwikcert. To promote your business market world wide ISO standards will help you. We assist you in the certification process in Saudi Arabia.

http://kwikcert.com/iso-certification-saudi-arabia/

41. sushanth -- 2018-03-13 10:30

Are you looking to advertise your products or services? We are there for you to help in billboards, hoarding,mobile van adverts, digital billboards, and LED hoardings in low cost

http://tecknex.com/billboards(ooh)ads.html

42. SimMechanics in Matlab Assignment Help -- 2018-03-13 10:31

This was a great and interesting article to read. I have really enjoyed all of this very cool information https://www.matlabhelponline.com/simmechanics-in-matlab-assignment-help-17680

43. Sarah Lai -- 2018-03-14 08:46
44. Craig -- 2018-03-24 16:33

This is advanced stuff, do you have any tutorials for beginners? My first experience is web design is this: destinflbeachweddings.com. I hope it's ok.

45. ainsleyalexavier@gmail.com -- 2018-03-28 09:10

Those understudies and student who are confronting the issue in their physic thinks about so they should attempt to Dissertation Writers Service join this discussion for getting every day reports regarding this matters.

46. translation price per word -- 2018-03-30 10:10
47. anonymous -- 2018-03-30 11:24

Assignmenthelp.us brings to you a comprehensive solution with an assurance of peerless writing style, implemented in every paper.

Click now: http://assignmenthelp.us/

48. translation price per word -- 2018-03-30 11:49

cThis is a really good tip particularly to those new to the blogosphere. Short but very precise information Many thanks for sharing this one. A must read article! https://wiya.pro/ https://wiya.pro/document-translation-services-boston/ https://wiya.pro/document-translation-services-los-angeles/ https://wiya.pro/document-translation-services-miami-fl/

49. translation price per word -- 2018-04-03 09:49

This is a really good tip particularly to those new to the blogosphere. Short but very precise information Many thanks for sharing this one. A must read article! https://alosalvaje.tumblr.com/ https://sassy-mum.tumblr.com/

https://bunnyshay.tumblr.com/

https://poppunkposerselloutskater.tumblr.com/

50. translation fees per hour -- 2018-04-03 09:50

Great blog here! Additionally your web site lots up very fast! What host are you using? Can I am getting your affiliate hyperlink on your host.

https://kluulesskeem.tumblr.com/ https://dampstar.tumblr.com/ https://masochist-babe.tumblr.com/

51. anonymous -- 2018-04-03 09:51

Way cool! Some very valid points! I appreciate you writing this post and the rest of the site is really good. company website https://activaterippermode.tumblr.com https://m-i-s-t-i-c--a.tumblr.com https://chocolatechipcunt.tumblr.com

52. anonymous -- 2018-04-03 09:51
53. translation price per word -- 2018-04-03 13:29

You are very brave focuses in this article. I would have never thought to be any of these in the event that I didn't run over this. Much appreciated.. <a href="https://www.seedszerverek.info/leiras/mars-translation-0">hourly rate for translation</a> <a href="https://www.boomeon.com/users/marstranslation">translation service cost</a> <a href="https://sites.google.com/site/protranslationservicesonline/">rate for translation per word</a>

54. translation price per word -- 2018-04-03 13:29

You are very brave focuses in this article. I would have never thought to be any of these in the event that I didn't run over this. Much appreciated! https://www.edocr.com/user/marstranslation http://www.seedszerverek.info/leiras/mars-translation-0 http://www.boomeon.com/users/marstranslation https://sites.google.com/site/protranslationservicesonline/

56. MBBS in China -- 2018-04-07 15:10

China gained expertise in its traditional medicine and allows students to study MBBS in China at a very low tuition fee and has opened its application for MBBS in China 2018.http://www.doctorabroad.co.in/course-cat/mbbs-in-china

57. anonymous -- 2018-04-11 11:43

You are very brave focuses in this article. I would have never thought to be any of these in the event that I didn't run over this. Much appreciated!

https://gamesstore.pro https://sparkstore.pro https://stylestore.pro https://vizava.pro

58. anonymous -- 2018-04-11 11:43

Great blog here! Additionally your web site lots up very fast! What host are you using? Can I am getting your affiliate hyperlink on your host. https://grandstore.pro https://globlestore.pro https://cavaton.pro https://cognian.pro https://gimzostore.pro

59. anonymous -- 2018-04-12 09:02

"You have picked up a very interesting topic and molded it perfectly to gain readers’ attention. What makes your article connect is the language, which is very easy to understand. Well, mission accomplished I must say! Coming to my work, I have been an active contributor to the powerful Android app, Falcon Super Cleaner. It is one of the most trusted cache cleaner designed to optimize the performance of your Android device with its actually quite easy-to-use interface." https://play.google.com/store/apps/details?id=com.falcon.clean.phone.master.junk.cleaner.battery.booster

60. faulaniakbar -- 2018-04-12 16:00

So whether your child is learning English for the very first time or is almost fluent, our unique approach will give them all the individual attention and opportunities they need to express themselves in a relaxed and supportive atmosphere. http://whazzup-u.com/profiles/blogs/solusi-alami-untuk-mengatasi-penyakit-hipertiroid

61. anonymous -- 2018-04-20 22:19

this is a really good tip particularly to those new to the blogosphere. Short but very precise information Many thanks for sharing this one. https://horseboxinsuranceuk.blogspot.com/

Add New Comment