- Edited
I'm using the AnimationTree state machine for animatiions. For some reason, the player's default idle animation won't play through when idling. It'll transition to the animation as far as I can tell, but again, won't play. Here's my code currently:
extends KinematicBody2D
#VARIABLES
export var walkSpeed: int;
export var runSpeed: int;
export var jumpForce: int;
export var gravity: int;
export var maxFallSpeed: int;
export var backslideSpeed: int;
export var health: int;
#CHECKS
var isCrouching: bool = false;
var isAttacking: bool = false;
var stateMachine;
var velocity: = Vector2();
func _ready():
stateMachine = $AnimationTree.get("parameters/playback");
func _process(_delta):
pass;
func input():
var current = stateMachine.get_current_node();
#MOVEMENT
if Input.is_action_pressed("right") and !isCrouching and !isAttacking:
$Sprite.scale.x = 1;
if Input.is_action_pressed("run"):
velocity.x = runSpeed;
if is_on_floor():
stateMachine.travel("Run");
else:
velocity.x = walkSpeed;
if is_on_floor():
stateMachine.travel("Trot");
elif Input.is_action_pressed("left") and !isCrouching and !isAttacking:
$Sprite.scale.x = -1;
if Input.is_action_pressed("run"):
velocity.x = -runSpeed;
if is_on_floor():
stateMachine.travel("Run");
else:
velocity.x = -walkSpeed;
if is_on_floor():
stateMachine.travel("Trot");
else:
velocity.x = 0;
# only play if not crouching
if !isCrouching and is_on_floor():
stateMachine.travel("Idle");
#JUMP
if is_on_floor() and Input.is_action_pressed("jump") and !isAttacking:
velocity.y = -jumpForce;
stateMachine.travel("Jump");
#FALL
if velocity.y >= 0 and !is_on_floor():
stateMachine.travel("Fall");
#CROUCH
if is_on_floor() and Input.is_action_pressed("crouch") and velocity.y == 0:
isCrouching = true;
$CrouchCollision.disabled = false;
$BodyCollision.disabled = true;
stateMachine.travel("Crouch");
else:
isCrouching = false;
$CrouchCollision.disabled = true;
$BodyCollision.disabled = false;
func _physics_process(delta):
input();
velocity.y += gravity * delta;
if velocity.y > maxFallSpeed:
velocity.y = maxFallSpeed;
velocity = move_and_slide(velocity, Vector2.UP);