How can I rotate Node3D around (360 degrees) by looped tween?

Godot Version

Godot v4.2.2 Stable Mono (C#)

Question

Hello! How can I rotate Node3D around on 360 degrees by looped tween? I write some code for tweening, but result not what I want. Cube rotates from Vector3(0f, 0f, 0f) to another Vector3(360f, 360f, 360f) using property “rotation_degrees” at TweenProperty method and antoher TweenProperty rotate back to Vector3(0f, 0f, 0f). But when the first tween is completed (360 degrees), the other tween does not rotate the cube further (around) and starts repeating the first tween only in reverse order.
At Unity I make this by LeanTween using rotateAround method — cube rotates non-stop around.

Code

Tween tween = CreateTween();
tween.SetEase(EaseType);
tween.SetTrans(TransitionType);
tween.SetLoops(10);
tween.TweenProperty(targetNode, "rotation_degrees", new Vector3(360f, 360f, 0f), Duration).SetDelay(Delay);
tween.TweenProperty(targetNode, "rotation_degrees", new Vector3(0f, 0f, 0f), Duration).SetDelay(Delay);

Could you use an AnimationPlayer instead? Or even targetNode.rotation.y += delta in process?

I don’t think a tween is quite right for this situation, but I think you could add a .From() to specify the starting rotation better.

var end = new Vector3(360f, 360f, 0f);
var start = new Vector3(0f, 0f, 0f);
tween.TweenProperty(targetNode, "rotation_degrees", end, Duration).From(start).SetDelay(Delay);
2 Likes

Yes, that’s what it takes. .From(StartVector) method causes the cube to spin around non-stop using tweener and no reverse it. Full tween code:

...
Tween tween = CreateTween();
tween.SetEase(EaseType);
tween.SetTrans(TransitionType);
tween.SetLoops();
tween.TweenProperty(targetNode, "rotation_degrees", EndVector, Duration)
     .From(StartVector)
     .SetDelay(Delay);

Thank you, @gertkeno! :grinning:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.