Created
October 24, 2019 20:58
-
-
Save juniornelson123/f9767bd1f2f3a96b1cb653a6cff02dbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends RigidBody2D | |
var pos = Vector2() | |
var move = false | |
export onready var positionObject = get_parent().get_node("position") | |
onready var tween = get_node("Tween") | |
func _ready(): | |
mode = MODE_STATIC | |
anim_form_start() | |
func _integrate_forces(state): | |
print(position) | |
func _physics_process(delta): | |
if Input.is_action_just_released("click"): | |
position = pos | |
move = false | |
apply_impulse(Vector2(0, 0), Vector2(10, -50)) | |
#anim_form_start() | |
if move: | |
#Recuperando diferenca entre a posicao do mouse e o ponto de origin | |
var diff_pos = get_global_mouse_position() - positionObject.position | |
#Limitando a posicao do vetor, utilizando metodo clamped e verificando a origem | |
position = positionObject.position + diff_pos.clamped(170) | |
pos = position | |
func _on_Player_input_event(viewport, event, shape_idx): | |
if event is InputEventMouseButton or event is InputEventScreenTouch: | |
mode = MODE_RIGID | |
move = true | |
func anim_form_start(): | |
if positionObject: | |
tween.interpolate_property(self, "position", position, positionObject.position, 1, Tween.TRANS_BACK, Tween.EASE_OUT) | |
tween.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment