• 2D
  • is_action_pressed not working as I'd expect

I want to be able to thrust in multiple directions but if I use IF statements instead of ELIF statements, only the last statement will work at all, i.e. only "lateral_right" will work. Why doesn't it work like "rot" does where I can use IF statements and they both work?

func get_input():
	rot = 0
	if Input.is_action_pressed("player_left"):
		rot -= rot_speed
	if Input.is_action_pressed("player_right"):
		rot += rot_speed
	if Input.is_action_pressed("player_thrust"):
		acc = Vector2(thrust, 0).rotated(rotation - PI / 2)
	elif Input.is_action_pressed("lateral_left"):
		acc = Vector2(thrust, 0).rotated(rotation + PI)
	elif Input.is_action_pressed("lateral_right"):
		acc = Vector2(thrust, 0).rotated(rotation)
	else:
		acc = Vector2(0, 0)

func _process(delta):

 # detect input
 get_input()
 
 # calculations
 acc -= vel * friction

 vel += acc * delta
 #vel += (acc + accl) * delta

 rotation += rot_speed * rot * delta
 
 # stay on screen
 if position.x >= screensize.x:
  position.x = 0
 if position.x < 0:
  position.x = screensize.x
 if position.y >= screensize.y:
  position.y = 0
 if position.y < 0:
  position.y = screensize.y
 
 position += vel * delta


Looking at the code above, I don't necessarily see anything that would be causing in issue. I've used is_action_pressed in Godot many times, and it should return a boolean that is true when the input is pressed and false when it is released.

The issue is likely because the actions for player_trust and laterial_left are not correctly setup or the name(s) for the input actions are slightly different in the code or the project settings.

I would check to see if the input actions are correctly bound to an input device first. If that does not work, then I would add some print statements to see if the code within the if/elif statements is executing or not. Another thing you could try is printing the results of Input.is_action_pressed("lateral_left") (for example) and see if it matches what you expect.