[SOLVED] How to tween a script property?

Hi guys! I am wondering how I can animate a property in my script?

For example, I have a property self.SPEED = 100 and I use it in update().

But when I receive a message, I want to reduce the value of that property to 0, with some of easing functions. How can I achieve that?

1 Like

You could use
go.animate(go.get_id(), "SPEED", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 2)
This should take the speed property to 0 in 2 seconds

Are you sure? Because I checked it before asking, and it doesn’t work, because of the error
'...' does not have any property called 'SPEED'

Let me test it real quick, I wrote the code from memory so it is possible that I have missed something.
Still, even if this does not work, you could always use lerp function

1 Like

Alright, this seems to be working:
go.animate("/plane#main", "SPEED", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 2)
Since the property belongs to the script and not the GO itself, you need to give the url of the script itself

1 Like

Ahaa! Okay, seems like it needs to be a link to a component. Since go.get_id() returns a hash of go, it wasn’t working. Thank you!

P.S. For future users, the universal way to use go.animate() in that case is to use "#" or msg.url() as a receiver. Because it returns a link to the current component

3 Likes