0 votes

Hello,
I got a kinematic player moving on a minimap by mouseclick, and changing scenes to special places, then coming back to minimap.
Trouble is, when coming back, the player globalposition is reset to the begining of the scene, not where he left the minimap. How to keep that position please?
Here's the script:

    extends Node2D
var terrain_speed = 1.0
var speed = 3*50 # triple speed
var first_input = false

func _input(event):
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
            var map_pos = $Map/Sprite.global_position
            var mouse_pos = get_global_mouse_position()
            var delta_position = mouse_pos - $Player.global_position # mouse click relative to player sprite
            var distance = map_pos.distance_to(mouse_pos)
            var duration = distance * terrain_speed/speed
            if first_input == false:
                first_input = true

            $Tween.interpolate_property($Map/Sprite, "global_position", map_pos, map_pos - delta_position, duration,
             Tween.TRANS_LINEAR, Tween.EASE_IN)
            $Tween.start()
            return
in Engine by (326 points)

Please log in or register to answer this question.

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.