0 votes

I'm currently learning basic 2d platformer movement and animation, where the player can use sword attacks to hit enemies. Animation for idle:ing, running, jumping and falling have all been working except the attack animation.

func _physics_process(delta):
motion.y += get_gravity() * delta

if Input.is_action_pressed("ui_right"):
    motion.x = min(motion.x+ACCELERATION, max_speed)

elif Input.is_action_pressed("ui_left"):
    motion.x = max(motion.x-ACCELERATION, -max_speed)

    motion.x = lerp(int(motion.x), 0, 0.2)

if is_on_floor():
    if Input.is_action_just_pressed("ui_up"):
        motion.y = JUMP_VELOCITY

if isAttacking == false and Input.is_action_just_pressed("Attack1"):
    isAttacking == true
    print("attack true")

motion = move_and_slide(motion, UP)

func Animation_player(motion):
if motion.y < 0 and isAttacking == false:
    if Input.is_action_pressed("ui_left"):
        $AnimatedSprite.flip_h = true
    if Input.is_action_pressed("ui_right"):
        $AnimatedSprite.flip_h = false
elif motion.y > 0:
elif motion.x > 0  and isAttacking == false:
    $AnimatedSprite.flip_h = false
elif motion.x < 0 and isAttacking == false:
    $AnimatedSprite.flip_h = true

func attack():
if isAttacking == true:

I've tried implementing the attack animation into the animation player function but that only causes the other animations to stop functioning.

Godot version 3.3.3
in Engine by (20 points)

1 Answer

+1 vote
Best answer

For starters, this:

isAttacking == true

Should be:

isAttacking = true

(note the difference between == and =)

by (13,810 points)
selected by

Thanks helped me solve the issue. Is there any documentation I can read about the difference between "=" and "==" because Im a bit uncertain.

Here's an overview (not gdscript specific, but still relevant):


The highlights...

  • = is an assignment operator. So var a = 10 assigns the value 10 to variable a.
  • == is an equality operator. So if a == 10 asks the question is the value of variable a 10?. It returns true or false based on the answer to the question.
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.