0 votes

So I was working on redoing my sprite from an AnimatedSprite2D to a Sprite2D that uses a AnimationPlayer for greater control for allowing multiple weapon pickups and such; however, after I made the update, the controller broke.
I copy pasted the code into a different CharacterBody2D and replicated what I had before I updated to the AnimationPlayer and the code seemed to work fine there.
The issue is the code no longer works for my updated character which is strange.

here is the main code:
func physicsprocess(_delta):

Movement

var directionLR = Input.get_axis("walk_left", "walk_right")
if directionLR:
    velocity.x = directionLR * SPEED
else:
    velocity.x = 0
var directionUD = Input.get_axis("walk_up", "walk_down")
if directionUD:
    velocity.y = directionUD * SPEED
else:
    velocity.y = 0
move_and_slide()

Animations

if Input.is_action_just_pressed("attack") and Input.get_axis("walk_left", "walk_right") or Input.is_action_just_pressed("attack") and Input.get_axis("walk_up", "walk_down"):
    #Attack Animation
    $Sprites/AnimationPlayer.play("walk_and_attack")
if Input.is_action_just_pressed("attack"):
    $Sprites/AnimationPlayer.play("attack")
if Input.get_axis("walk_left", "walk_right") or Input.get_axis("walk_left", "walk_right") and Input.is_action_just_released("attack") or Input.get_axis("walk_up", "walk_down") or Input.get_axis("walk_up", "walk_down") and Input.is_action_just_released("attack"):
    #Run animation
    $Sprites/AnimationPlayer.play("walk")
elif Input.is_action_just_released("attack") or Input.is_action_just_released("walk_left") or Input.is_action_just_released("walk_right") or Input.is_action_just_released("walk_up") or Input.is_action_just_released("walk_down"):
    #Idle Animation
    $Sprites/AnimationPlayer.play("idle")
else:
    $Sprites/AnimationPlayer.play("idle")
Godot version 4.0
in Engine by (12 points)

1 Answer

0 votes

Make Debug Logs with print
https://docs.godotengine.org/en/3.1/classes/[email protected]#class-gdscript-method-print
You can check all variables and loops

by (372 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.