My animation state machine doesnt work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By selavi

trying to create state machine but it doesnt seem to work … please see screenshot maybe i am missing something there…

Screenshot by Lightshot

may there be something that interfere ? I am new so i think i am using kinda bulky code with lots of not so well optimisex stuff…

i will add all code here:

extends KinematicBody2D

var bullet = preload(“res://bullet.tscn”)

export (int) var speed = 500
export (int) var jump_speed = -1100
export (int) var gravity = 4000

var velocity = Vector2.ZERO
var state_machine
var health = Global.health
var healthbar = “Camera2D/healthbar”

var prone = false

func _ready():
state_machine = $chest/AnimationTree.get(“parameters/playback”)

$Camera2D/healthbar.value = Global.health
$Camera2D/Oxyhud/ProgressBar.value = Global.oxy

func get_input():
var current = state_machine.get_current_node()
var dir = 0
if Input.is_action_pressed(“walk_right”):
dir += 1
state_machine.travel(“Walk_Right”)
$chest.set_scale(Vector2(0.3,0.3))
$Muzzle.position = Vector2(40,0)

if Input.is_action_pressed("walk_left"):
	dir -= 1
	$chest.set_scale(Vector2(-0.3,0.3))
	state_machine.travel("Walk_Left")

if dir != 0:
	velocity.x = lerp(velocity.x, dir * speed, acceleration)
else:
	velocity.x = lerp(velocity.x, 0, friction)

func shoot():
Global.ammo -= 1
var bul = bullet.instance()
get_parent().add_child(bul)
bul.position = $Muzzle.global_position
if $Muzzle.position == Vector2(-40,0):
bul.bdirection(-1)

func _physics_process(delta):

$Camera2D/healthbar.value = Global.health
	
if Global.health <= 0:
	get_tree().change_scene("mygame")
		
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if Input.is_action_just_pressed("jump"):
	if is_on_floor():
		state_machine.travel("Jump")
		velocity.y = jump_speed
if Input.is_action_pressed("prone"):
	if is_on_floor() and Input.is_action_just_pressed("jump"):
		velocity.y = jump_speed * 2
		Global.oxy -= 200
		
		
if Input.is_action_just_pressed("shoot") and Global.ammo > 0:
	state_machine.travel("Shoot")
	shoot()
if Global.oxy <= 0:
	death()

if Global.health <= 0:
	death()

please reformat your code

whiteshampoo | 2020-11-03 08:15