0 votes

So what I want to do is to move a node2d's position up and down couple of pixels constantly at intervals to create a jittering effect. What I have so far is a function "onMove" that gets called every 1 second. Or is there any other way of achieving this effect?

  func _ready():
        var viewport = get_viewport().get_rect().size
        x = viewport.x
        y = viewport.y
        set_global_pos(Vector2(x/2,y/4))

        var timer = Timer.new()
        timer.set_timer_process_mode(0)
        timer.set_wait_time(1)
        timer.connect("timeout", self, "onMove")
        add_child(timer)
        timer.start()

        #Sets frame updates
        set_fixed_process(true)

        #Sets UI
        set_process(true)

        #Set inputs 
        set_process_input(true)

    func onMove():
        print("here")
in Engine by (60 points)
edited by

1 Answer

0 votes
Best answer

Thats one way to do it, there are always different ways to do things. Others that come to my mind:

  • use an animation player
  • use a sin() function to offset the translation, you can use clamp() to make it more jittery and less smooth
by (290 points)
selected by

Thank you! I've went with the animation player. So much cleaner.

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.