Smoof.lua - Move things smoothly!

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Smoof.lua - Move things smoothly!

Post by veethree »

Hi. I've made a thing.

Smoof.lua is this lovely function wrapped up in a library:

Code: Select all

value = value + (target - value) * smoothing
It's more properly documented on Github, But here's the basics.


Load it

Code: Select all

smoof = require("smoof.lua")
Update it

Code: Select all

smoof:update(dt)
Have some type of table containing values

Code: Select all

object = {x = 0, y = 0}
Smoothly change whatever values the object contains like so

Code: Select all

smoof:new(object, {x = 32})
Repeat that a few times and you have:
Image

You can download this demo below if you want to mess around with it.
Attachments
smoof.lua
1.1
(4.82 KiB) Downloaded 168 times
smoof_demo.love
(3.11 KiB) Downloaded 187 times
Last edited by veethree on Tue Sep 14, 2021 12:50 am, edited 3 times in total.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Smoof.lua - Move things smoothly!

Post by Gunroar:Cannon() »

Nice name. Like a tweening thing.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Smoof.lua - Move things smoothly!

Post by pgimeno »

Good but the speed depends on the frame rate.

https://www.rorydriscoll.com/2016/03/07 ... sing-lerp/
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Smoof.lua - Move things smoothly!

Post by veethree »

pgimeno wrote: Sun Sep 12, 2021 7:41 pm Good but the speed depends on the frame rate.

https://www.rorydriscoll.com/2016/03/07 ... sing-lerp/
Well darn. I thought multiplying by dt had me covered. Thanks for pointing this out, I'll look into fixing it!

EDIT: I've fixed it. It's now framerate independent. Thanks again pgimeno!
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Smoof.lua - Move things smoothly!

Post by yetneverdone »

Amazing! Just curious, how does this compare to Flux?
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Smoof.lua - Move things smoothly!

Post by veethree »

yetneverdone wrote: Mon Sep 13, 2021 3:46 am Amazing! Just curious, how does this compare to Flux?
Well flux is pretty much better in every way. And so is tween. There is no reason why one should use smoof instead of tween or flux. :)
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Smoof.lua - Move things smoothly!

Post by togFox »

I love a guy/gal that knows his/her place in the universe. :)
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 52 guests