Is_on_ceiling() acts as if it is is_on_floor()

Godot Version

Godot 4

Question

Using the code below is_on_ceiling() returns true when the player is on the floor and is_on_floor() returns true when the player is on the ceiling. Am I doing something wrong? I can’t seem to figure out why this happens?

func _physics_process(delta):
	if not is_on_ceiling():
		velocity.y += 980 * delta
	else:
		print("On floor")
		
	if is_on_floor():
		print("On ceiling")
		
	if Input.is_action_just_pressed("up"):
		velocity.y = 400
	
	var direction = Input.get_axis("left", "right")
	if direction:
		velocity.x = direction * 130
	else:
		velocity.x = move_toward(velocity.x, 0, 130)

	move_and_slide()

Did you change the up direction?

1 Like

It’s still equal to x: 0 y: -1

i think for is_on_floor and is_on_ceiling to work correctly you need to actually move into the floor / ceiling each frame. so if velocity.y is 0 then it won’t work, so you need to apply gravity every frame unconditionally

also you should set the velocity.y to -400 not 400 when you jump

2 Likes

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