Can anyone show me what IAM doing rong

Godot Version

func _physics_process(_delta):

animation()

hundleinput()
if Input.is_action_pressed("ui_down"):
	ani.play("run")
if Input.is_action_pressed("ui_up"):
	ani.play("run")
if Input.is_action_pressed("ui_right"):
	ani.play("run")
	ani.flip_h = true
if Input.is_action_pressed("ui_left"):
	ani.play("run")
	ani.flip_h = false
else :

	ani.play("idel")

move_and_slide()

Question

i cant seem to make the animation work when i flib h it,s just flib the idel animation first fram

The first 3 if statements you’re using are all standalone checks, but your last one has an else after it. That means that after all the first group of checks are done (regardless if they’re true or false) the last one will check for ui_left and if that’s not true, you automatically play the idel animation instead.
Basically, all the code to play animations before your ui_left option gets overwritten because the last statement will be either true (and set left) or false (and set idel).

2 Likes

Building on @Hectate 's answer to fix this issue, use an elif. This links the branches together so that only one branch may trigger.

Also use code formatting by pressing the </> button a new line, then pasting like so

```
type or paste code here
```

if Input.is_action_pressed("ui_down"):
	ani.play("run")
elif Input.is_action_pressed("ui_up"):
	ani.play("run")
elif Input.is_action_pressed("ui_right"):
	ani.play("run")
	ani.flip_h = true
elif Input.is_action_pressed("ui_left"):
	ani.play("run")
	ani.flip_h = false
else :
	ani.play("idel")
2 Likes

For anyone looking for a similar problem the tow Replay is correct but I choose the more general off the topic

Thanks a lot

I didn’t think that was a problem :sweat_smile: well know I know more about if statement thanks :rose: