HensCodes
A downloadable asset pack
CHARACTER 2D TOPDOWN
CODE
###########
var velocity = Vector2()
var speed = 100
func _physics_process(_delta):
mexer()
animar()
func mexer():
var direction_vector:Vector2 = Vector2(
Input.get_action_strength("Direita") - Input.get_action_strength("Esquerda"),
Input.get_action_strength("Baixo") - Input.get_action_strength("Cima")
).normalized()
velocity = direction_vector * speed
velocity = move_and_slide(velocity)
func animar():
if Input.is_action_pressed("Cima"):
$AnimCoolboy.play("Cima")
elif Input.is_action_pressed("Baixo"):
$AnimCoolboy.play("Baixo")
elif Input.is_action_pressed("Direita"):
$AnimCoolboy.play("Lado")
$Sprite.flip_h = false
elif Input.is_action_pressed("Esquerda"):
$AnimCoolboy.play("Lado")
$Sprite.flip_h = true
else:
$AnimCoolboy.play("Parado")
###########