0 votes

Godot 2.1.4 Stable Linux

Hi all,

Forgetting the easing for now. How can I move a sprite from the position of one object to the position of another?

For example, I can get the position of the two locations and imagine they end up being Vector2(100,100) and Vector2(10,10).

I've looked at making the sprite a child of a Kinematic2D and of a RigidBody but when I play with Vectors etc I'm only pushing/moving them in the direction of the vector. I need to know how to say Move towards 10,10.

Is there a way to do that? Of course there is :-) I just can't find a simple answer out there is all. Can anyone lend a helping Christmas hand? :-)

in Engine by (824 points)
edited by

1 Answer

+3 votes
Best answer

So I found the answer. It turns out it's Tweening, for anyone in the future. Here's something to help:

export var to           = Vector2(60,100)   #where we're moving to when we leave screen
    export var from         = Vector2(250,450)      #which part of the pipeline we travel back to
    export var speed            = 400       #fast sprite?  slow sprite?
    onready var tween = get_node("Tween")
    var property = "transform/pos"

    func _ready():

        #set our start position
        moveToTarget(to, from)

    func moveToTarget(end, start):
        var distance = start.distance_to(end)
        var time = distance / speed

        if tween.is_active():
            tween.stop(self, property)
            tween.interpolate_property(self, property, start, end, time, Tween.TRANS_LINEAR, Tween.EASE_IN)
            tween.interpolate_property(self, "transform/scale", Vector2(0,0), Vector2(1,1), .8, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
by (824 points)
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.
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 webmaster@godotengine.org with your username.