PirateTreasureHunt/scenes/pirate.gd

33 lines
798 B
GDScript

extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2()
var target = Vector2()
func get_input():
velocity = Vector2()
if Input.is_action_pressed("walk_right"):
velocity.x += 1
if Input.is_action_pressed("walk_left"):
velocity.x -= 1
if Input.is_action_pressed("walk_down"):
velocity.y += 1
if Input.is_action_pressed("walk_up"):
velocity.y -= 1
velocity = velocity.normalized() * speed
func _physics_process(delta):
velocity = position.direction_to(target) * speed
if position.distance_to(target) > 5:
velocity = move_and_slide(velocity)
# Called when the node enters the scene tree for the first time.
func _ready():
position = Vector2(0,0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass