- Edited
Hey everyone, so I can't seem to have animated sprite and movement work together in the same code. I want my player to be able to animate in different directions when he walks. Here is my code. Thanks in advanced
extends Kinematicbody2D
const FRICTION = 10
const ACCELERATION = 10
const MAX_SPEED = 100
var velocity = Vector2.ZERO
func _process(delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")i
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:
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION)
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION)
move_and_slide(velocity)
onready var _animated_sprite = $AnimatedSprite
if Input.is_action_pressed("ui_right"):
_animated_sprite.play("right")
else:
_animated_sprite.stop()
if Input.is_action_pressed("ui_left"):
_animated_sprite.play("left")
else:
_animated_sprite.stop()
if Input.is_action_pressed("ui_up"):
_animated_sprite.play("back")
else:
_animated_sprite.stop()
if Input.is_action_pressed("ui_down"):
_animated_sprite.play("front")
else:
_animated_sprite.stop()