Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Sonicpen |
Hey everyone, currently I’m following a action rpg tutorial from a youtuber. Everything was going fine until i kinda messed with something unknowingly when i was showcasing my friends how the animationtree works. When i press any walking key the character walks for 1 animation loop. after the frames are over and it should repeat the animation, it doesnt. It stops at the last frame. Until i change the state to roll or attack it walks with the stuck frame. Does anyone know where i messed up with? I will share the script but i know that wasn’t something i touched. Thank you!
Here is the player script.
extends KinematicBody2D
const acc = 500
const max_speed = 100
const friction = 500
const roll_speed = 125
enum {MOVE,ROLL,ATTACK}
var state = MOVE
var velocity = Vector2.ZERO
var roll_vector = Vector2.LEFT
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
func _ready():
animationTree.active = true
func _physics_process(delta):
match state:
MOVE:
move_state(delta)
ATTACK:
attack_state(delta)
ROLL:
roll_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:
roll_vector = input_vector
animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/walk/blend_position", input_vector)
animationTree.set("parameters/Attack/blend_position", input_vector)
animationTree.set("parameters/Roll/blend_position", input_vector)
animationState.travel("walk")
velocity = velocity.move_toward(input_vector*max_speed, acc*delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, friction*delta)
move()
if Input.is_action_just_pressed("roll"):
state = ROLL
if Input.is_action_just_pressed("attack"):
state = ATTACK
func roll_state(delta):
velocity = roll_vector * roll_speed
animationState.travel("Roll")
move()
func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel("Attack")
func move():
velocity = move_and_slide(velocity)
func roll_animation_finished():
velocity = Vector2.ZERO
state = MOVE
func attack_animation_finished():
state = MOVE