is_on_floor is not working in the game I am making.

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

var motion = Vector2(0,0)

const SPEED = 500
const GRAVITY = 5
const UP = Vector2(0,-1)
const JUMP = -3000

func _physics_process(delta):
if Input.is_action_pressed(“ui_up”):
print(“should jump but isnt”)

func apply_gravity():
if not is_on_floor():
motion.y += GRAVITY
motion.y = GRAVITY

func move():
if Input.is_action_pressed(“ui_left”) and not Input.is_action_pressed(“ui_right”):
motion.x = -SPEED
elif Input.is_action_pressed(“ui_right”) and not Input.is_action_pressed(“ui_left”):
motion.x = SPEED
motion.x = 0

func jump():
if Input.is_action_just_pressed(“ui_up”) and is_on_floor():
motion.y = JUMP

:bust_in_silhouette: Reply From: Magso

Your move_and_slide doesn’t have an up direction so it defaults to Vector2.ZERO. It mentions in the docs ‘used to determine what is a wall and what is a floor or a ceiling’

move_and_slide(motion, Vector2.UP)

Wow! This completely solved my problem! It’s been a whole month since I was thinking why this wasn’t working just for me and now I realized it’s because of me not reading the docs properly.

spoicat | 2021-05-27 01:09