Hi!, I'm new to godot and i was following this tutorial on youtube everything was fine till i decided to do the attack animation like the kinematicbody doesnt move at all. anybody know how to fix it?
extends KinematicBody2D
const FRICTION = 15
enum{
MOVE,
ATTACK
}
var state = MOVE
var velocity = Vector2.ZERO
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
func _ready():
animationTree.active= true
#state machines baby!!!!!
func _physics_process(delta):
match state:
MOVE:
move_state(delta)
ATTACK:
attack_state(delta)
func move_state(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")
if input_vector != Vector2.ZERO:
animationTree.set("parameters/idle/blend_position", input_vector)
animationTree.set("parameters/walk/blend_position", input_vector)
animationTree.set("parameters/attack/blend_position", input_vector)
animationState.travel("walk")
velocity = velocity.move_toward(input_vector * FRICTION * delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
velocity = move_and_slide(velocity)
if Input.is_action_just_pressed("Attack"):
state = ATTACK
func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel("Attack")
func attack_animation_finished():
state = MOVE