extends KinematicBody

var gravity = Vector3.DOWN * 12  # strength of gravity

var speed = 4  # movement speed

var jump_speed = 12  # jump strength

var spin = 0.1  # rotation speed

var velocity = Vector3()
var rotang = Vector3()

var target = Transform()

var id

#func _ready():


func get_input():
	velocity = target.origin - self.get_global_transform().origin
	rotang = acos(target.basis.xform(Vector3(0, 0, 1)).x) - acos(self.get_global_transform().basis.xform(Vector3(0, 0, 1)).x)
	
func _physics_process(delta):
	velocity += gravity * delta
	get_input()
	velocity = move_and_slide(velocity, Vector3.UP)
	rotate_y(rotang)
	
	
func _unhandled_input(event):
	if event is InputEventMouseMotion:
		if event.relative.x > 0:
			rotate_y(-lerp(0, spin, event.relative.x/10))
		elif event.relative.x < 0:
			rotate_y(-lerp(0, spin, event.relative.x/10))

func set_target(trans):
	self.target = trans
