Hello. Happy <insert today here>.
Heeeeelp!! So! I have a KinematicBody2D that is my Player. It can move with the following:
var moveSpeed : int = 250
func _physics_process (delta):
vel = Vector2()
if has_control == true:
if Input.is_action_pressed("move_up"):
vel.y -= 1
facingDir = Vector2(0, -1)
if Input.is_action_pressed("move_down"):
vel.y += 1
facingDir = Vector2(0, 1)
if Input.is_action_pressed("move_left"):
vel.x -= 1
facingDir = Vector2(-1, 0)
if Input.is_action_pressed("move_right"):
vel.x += 1
facingDir = Vector2(1, 0)
When the player touches an Area2D, it removes control of the Player using:
has_control = false
What I want to happen next is to pass specific coordinates (let's say 500, 100) to the player through a signal and have the player move towards that coordinate. I've got the signal part down, but I can't seem to figure out the moving part. I've tried:
func move_to_battle_position(x, y)
position = position.move_toward(Vector2(x, y), delta * moveSpeed)
But delta isn't defined there. Everything I read says that this needs to be in the physics_process(delta) or process(delta) function, but I want to be able to call it once when needed and then shut it down when the Player reaches the coordinate I give to it.
How can I achieve this? Any help would be really awesome!