Why is the code not passing the if-elif check

Godot Version

4.4

In my code, I want to check the rotation of the player, which I am doing via the model node for this project, and use that to determine whether the player model would be in normal footing or goofy footing (this being a skateboard game).

After some testing, it seems that the problem is that the code somehow does not pass the if-elif statements and do the logic I ask it to.

So I am not sure where it is and I don’t feel rested enough to discern it today. I would like some help identifying the potential problem.

The relevant code is below:

extends CharacterBody3D


signal change_footing(footing: Footing.footing)

var in_air = false

var last_grounded_angle: float

@onready var model = $Model

func _process(delta: float) -> void:
	if is_on_floor() and in_air:
		check_footing()
	elif !is_on_floor():
		if !in_air:
			in_air = true
			last_grounded_angle = model.rotation_degrees.y

func check_footing() -> void:
	in_air = false
	var air_rotation = int(abs(last_grounded_angle - model.rotation_degrees.y))
	if air_rotation < 160 and air_rotation > 200:
		target_footing = GOOFY_FOOTING_ROTATION
		change_footing.emit(Footing.footing.Goofy)
	elif air_rotation < 20 and air_rotation > 340:
		target_footing = NORMAL_FOOTING_ROTATION
		change_footing.emit(Footing.footing.Normal)

Both of these conditions are impossible to meet. you cannot have a value less than 160 and greater than 200. you cannot have a value that is less than 20 and greater than 340.

Maybe you mean to use or, as a value can be < 160 or > 200, meaning it only excludes values between 160-200. But you would need to flip your if/elif order for other logical reasons.

3 Likes

Ah, so I just mixed up the conditions, cause its supposed to check for 160 < x < 200

In that case, you just have to flip your comparison operators:

if air_rotation > 160 and air_rotation < 200:

If air_rotation is both greater than 160 and less than 200, that means it is between the two values, as your 160 < x < 200 expression mentions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.