HeartBeast/script/player/Player.gd

29 lines
846 B
GDScript3
Raw Normal View History

2021-04-03 23:27:13 +02:00
extends KinematicBody2D
var velocity = Vector2.ZERO
const MAX_SPEED = 80
const ACCELERATION = 500
const FRICTION = 500
onready var animationPlayer = $AnimationPlayer
func _physics_process(delta):
var input_vector=Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
if input_vector.x > 0:
animationPlayer.play("Walk_Right")
if input_vector.x < 0:
animationPlayer.play("Walk_Left")
velocity = velocity.move_toward(input_vector*MAX_SPEED,ACCELERATION*delta)
else:
animationPlayer.play("Idle_Right")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)
velocity = move_and_slide(velocity)