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: 848
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 77 times
smoof_demo.love
(3.11 KiB) Downloaded 79 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: 592
Joined: Thu Dec 10, 2020 1:57 am

Re: Smoof.lua - Move things smoothly!

Post by Gunroar:Cannon() »

Nice name. Like a tweening thing.
Why can't pirates code in lua? Because they spend to much time at C! :P

-It might look like nonsense :roll: but there's so much proof.
-Some more if you pls... :? .
It has to be real then, all that talk about the end :shock: .
-How to be saved :huh:
User avatar
veethree
Inner party member
Posts: 848
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: 397
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: 848
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. :)
togFox
Party member
Posts: 392
Joined: Sat Jan 30, 2021 9:46 am

Re: Smoof.lua - Move things smoothly!

Post by togFox »

I love a guy/gal that knows his/her place in the universe. :)
Post Reply

Who is online

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