This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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)

else:
    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)
Animation_player(motion)
print(motion)
pass

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

func attack():
if isAttacking == true:
    $AnimatedSprite.play("Attack")

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 (22,704 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):

https://www.geeksforgeeks.org/what-is-the-difference-between-assignment-and-equal-to-operators/#:~:text=The%20%E2%80%9C%3D%E2%80%9D%20is%20an%20assignment,the%20variable%20on%20the%20left.&text=The%20'%3D%3D'%20operator%20checks%20whether,Otherwise%20it%20returns%20false.

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.