Hi, I'm kinda new to Godot game development, and right now I'm following a Godot RPG tutorial series. I have a problem with the animation I'm making and I can't figure it out so I thought I might try to ask on a forum.
It would be very helpful to try to look into it.
https://streamable.com/zcuviu
https://streamable.com/zcuviu
this is a video of the animation
Please tell me if you need anything more
this is the player node~~~~ code
extends KinematicBody2D
const FRICTION = 450
const ACCELERATION = 300
const MAX_SPEED = 75
enum {
MOVE,
ROLL,
ATTACK
}
var state = MOVE
var velocity = Vector2.ZERO
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
func _physics_process(delta):
match state:
MOVE:
move_state(delta)
ROLL:
pass
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")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
#this is setting the animation with an animation tree
animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/Run/blend_position", input_vector)
animationTree.set("parameters/Attack/blend_position", input_vector)
animationState.travel("Run")
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
move_and_collide(velocity * delta)
if Input.is_action_just_pressed("attack"):
state = ATTACK
func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel("Attack")
func attack_animation_finished():
velocity = Vector2.ZERO
state = MOVE
animationState.travel("Idle")