Attack animation not playing

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

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.

:bust_in_silhouette: Reply From: jgodfrey

For starters, this:

isAttacking == true

Should be:

isAttacking = true

(note the difference between == and =)

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

WimpyBaby | 2022-02-20 13:15

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

What is the difference between = (Assignment) and == (Equal to) operators - GeeksforGeeks.

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.

jgodfrey | 2022-02-20 16:28