0 votes

I'm playing around with Path2D and it is something that I may want to use to animate things like chains. I've been wondering if there is some technique for quickly animating say 30-40 objects on a path, getting them to complete a full revolution, relative to their starting location on the path.

in Engine by (5,252 points)

1 Answer

0 votes
Best answer

I suppose nevermind. ^_^

AnimationPlayer doesn't seem to be suited for keyframing the unit offsets.

The solution that seems to work for me is this, hopefully there aren't any floating point issues:

extends Path2D

export var step = .1

func _ready():

func _process(delta):

    for seg in get_children():
        var uo = seg.get_unit_offset()

        uo += step * delta
        # if(uo > 1): uo -= 1
        # edit: mod is a safer bet
            if(uo > 1 or uo < -1): uo = fmod(uo, 1)

by (5,252 points)
edited by

I have made something like that too, with the option to add any ammount of nodepaths by demand, you can adapt that to the path length for a cleaner scene (I hate to see many nodepaths there >_>)

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.