Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method/PropertyTweener lost ability to follow values in 4.0 #54294

Open
HybridEidolon opened this issue Oct 27, 2021 · 4 comments
Open

Method/PropertyTweener lost ability to follow values in 4.0 #54294

HybridEidolon opened this issue Oct 27, 2021 · 4 comments

Comments

@HybridEidolon
Copy link
Contributor

Godot version

v4.0.dev.20211015.official [f113dc9]

System information

Windows 10

Issue description

In the 3.x version of the Tween API, there were follow_method and follow_property, which could be used to tween to a dynamic target value. The new Tween API (#41794) does not have this functionality, with no replacement.

Fix proposal: Extend the existing Method and Property Tweeners to be able to follow a value which is evaluated during tween processing, instead of a fixed value at Tween creation.

var tween: Tween = create_tween()
# Follow a target node's global_position property over 5 seconds
var tweener: PropertyTweener = tween.follow_property(self, "global_position", other, "global_position", 5.0)
var tweener2: MethodTweener = tween.follow_method(self, "my_method", other, "my_method", 5.0)

Steps to reproduce

Migrate any 3.x Tween-reliant code which uses the follow_method and follow_property functions.

Minimal reproduction project

No response

@YuriSizov
Copy link
Contributor

cc @KoBeWi

@KoBeWi
Copy link
Member

KoBeWi commented Oct 27, 2021

There is a replacement:

var me = self
var target = $Some/Node
create_tween().tween_method(func(t): me.global_position = target.global_position, 0, 1, 5)

I was initially confused by this method, but after I realized what it does it was left out, because it's super-specific and possible to achieve in a different way.

@HybridEidolon
Copy link
Contributor Author

The following does work, yeah:

var me = self
var starting_position = me.global_position
tween.tween_method(func(t): me.global_position = starting_position.lerp(target.global_position, t), 0.0, 1.0, 5.0)

It requires more boilerplate than the previous way to do this, though. But perhaps it is better to have a more general method for this instead of the specific follow methods, now that there are inline anonymous functions. Maybe this should be noted in the release notes or the Tween docs for migrating existing code.

(Separately, I don't know what the closure rules are for GDScript 2, but if anonymous funcs closed over the outer scope's self, it would match the behavior of () => syntax in JavaScript, which I think would help some people moving from web game scripting.)

@akien-mga akien-mga added this to the 4.0 milestone Nov 1, 2021
@ghost
Copy link

ghost commented Jul 23, 2022

Hi.
The above works but, IMHO, it feels like a workaround.
I would prefer to have the specific follow methods.
Maybe it is just a matter of taste.

@YuriSizov YuriSizov modified the milestones: 4.0, 4.x Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants