0 votes

I've been following the instructions of how to create a "jump"-like Tween transition in Godot 3.0 over here: https://godotengine.org/qa/14993/how-can-i-achieve-set_pos-as-a-parable-with-tween-node?show=14993#q14993

However, for some reason it doesn't seem to work in Godot 3.0. Apparently, whenever I create multiple Tween transitions to form a Tween sequence, it only performs one of them. I've tried various combinations, it doesn't seem to work as intended.

Does anyone have any suggestions of how to write a jump like animation with Tweens just like the one described in the link in Godot 3.0?

asked Jan 21, 2019 in Engine by AbstractGameDev (16 points)

1 Answer

+1 vote

If you must use Tweens, you could do something like this.

func parabolic_movement(target_node, start_x, end_x, start_y, end_y, duration):

    # tween x position linearly across duration
    tween1.interpolate_property(target_node, "global_position:x", start_x, end_x, duration, Tween.TRANS_LINEAR, Tween.TRANS_LINEAR)

    tween1.start()

    # tween y position in two parts, each across duration/2

    # first tween upwards and wait for the tween to finish
    tween2.interpolate_property(target_node, "global_position:y", start_y, end_y, duration/2, Tween.TRANS_SINE, Tween.EASE_OUT)    
    tween2.start()

    yield(tween2, "tween_completed")

    # then tween downwards
    tween2.interpolate_property(target_node, "global_position:y", end_y, start_y, duration/2, Tween.TRANS_SINE, Tween.EASE_IN)
    tween2.start()

But typically I would just code this kind of movement directly in _physics_process() using variables to represent velocity, acceleration, and gravity.

answered Jan 21, 2019 by Diet Estus (1,504 points)
edited Jan 21, 2019 by Diet Estus

Hey, thanks for the answer. I implemented it and it works. You're right about it being more logical to code a structure for a jump rather than using a Tween.

I experimented with the idea of drawing a line, via the _draw(): function, set its opacity to 0, converting it into a PoolVector2Array, then apply it to a Path2D / PathFollow, which the object would follow. But, I'm not certain how to handle that. It's a bit more complex, and I'm still learning the optimal use of Godot. I'd honestly rather do that, but apparently I can't make it work properly.

If you have any ideas for such a "limited", restrained, one-time jump, I'm listening. It's not for a player input by the way, it's a for an player item.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.