godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.08k stars 69 forks source link

Implement tween_wiggle_property() / tween_random_value #6771

Open CarpenterBlue opened 1 year ago

CarpenterBlue commented 1 year ago

Describe the project you are working on

Boss fight with Scorpion enemy, I need to wiggle the claws for a bit so I can telegraph launching them towards the Player. Would also use it during cutscenes if I had the chance.

Describe the problem or limitation you are having in your project

I have to make a wiggle function every time I have to do that or make a autoload with the function. Something so common could fit with the tweens.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The current way of doing it is not readily apparent or available and still somewhat clunky

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

var t = create_tween()
t.tween_wiggle_property(node,"property",base_value,lower_wiggle_amount,higher_wiggle_amount,duration)

The node's property will be wiggled for the duration

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, here is my solution for the attack.

var t = create_tween()

var snapshot = claw.translation
t.tween_method(self, "wiggle",snapshot,snapshot,.5)

func wiggle(value):
    var v = .25
    claw.translation = value
    claw.translation.x += rand_range(-v,v)
    claw.translation.z += rand_range(-v,v)

Is there a reason why this should be core and not an add-on in the asset library?

It's quality of life feature that can be used in various circumstances. Camera shake Telegraphing Cutscenes Randomizing values for gameplay logic driven by tweens

Calinou commented 1 year ago

Isn't the implementation you propose dependent on framerate, since it sets a new random position every frame? We should avoid situations where an animation looks different depending on framerate.

CarpenterBlue commented 1 year ago

I have no idea, I have simple non-resource extensive 2D game so it never really comes into play. Either way, I honestly don't really care with wiggle but if you have better solution I would love to hear it.

MewPurPur commented 1 year ago

This isn't descriptive enough, I don't really get what you want. "Wiggling a property" is quite abstract, do you expect something like the text shake event in RichTextLabel? If that is the case, then I agree with having some kind of similar built-in solution for common basic animations that act on an object's transform. I don't think Tween is the place for it, but I can't really think of a better solution myself.

Calinou commented 1 year ago

Isn't the implementation you propose dependent on framerate, since it sets a new random position every frame? We should avoid situations where an animation looks different depending on framerate.

To add to my previous comment: to avoid this effect, noise is typically used as its effective "speed" won't vary based on framerate.

An alternative is to pick a random value a fixed amount of times per second (e.g. 10 Hz) and smoothly interpolate between those values over time.