Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DanniloSN | |
Old Version | Published before Godot 3 was released. |
I’m trying to do a point-and-click, I’m using set_pos (), but when the character reaches the destination, it’s quivering without stopping. Can you help me fix this? Or replace with the move?
extends Node2D
const VELOCIDADE = 100.0
onready var personagem = get_node("mega")
var direcao
var movimento
var destino = Vector2()
func _ready():
set_process(true)
set_process_input(true)
func _process(delta):
var posicao_personagem = get_node("mega").get_pos()
```
direcao = (destino - posicao_personagem).normalized()
movimento = delta * VELOCIDADE
if posicao_personagem + direcao > destino:
personagem.set_pos(posicao_personagem + direcao * movimento)
get_node("Label").set_text(str(personagem.get_pos()))
```
func _input(event):
if event.type == InputEvent.MOUSE_BUTTON and event.is_pressed():
destino = event.pos
print(destino)