0 votes

So basically every time i move my player the is_on _floor function keeps switching to true and false even though I'm on the floor.

I'm using a tilemap to give collisions to my floor and viewed the collisions shapes while running and there wasn't any gaps between the tiles.

I'm using Godot 3.1

asked Jun 16, 2019 in Projects by Newby (383 points)

What your move_and_slide call looks like?

found out my player is bobbling up ad down but very tiny bobs.
don't know why however.

any ways here's the script

Player Move script
if Input.is_action_pressed("ui_right"): facing=1 $anim.play("Right") motion.x=SPEED elif Input.is_action_pressed("ui_left"): facing=-1 $anim.play("Left") motion.x=-SPEED else: motion.x=0

Extends script for player

extends KinematicBody2D

const MAXSPEED=120
const JUMPPOWER=270
const JUMP=Vector2(0,-1)
const GRAV=10

var motion=Vector2()

func move():
    if !is_on_floor():

1 Answer

+2 votes
Best answer

This is not how is_on_floor() works.

The value of is_on_floor() is set by move_and_slide(). Since you're using the previous frame's value and then moving with no gravity, the value is being set to false.

You should only check is_on_floor() after calling move_and_slide(). And if you disable gravity, you won't be moving into the floor, and therefore it there won't be a collision with the floor.

func move():
    motion.y += GRAV
    motion = move_and_slide(motion, JUMP)
    # now check is_on_floor()
answered Jun 16, 2019 by kidscancode (17,772 points)
selected Jun 16, 2019 by Newby

This answer should be posted in the front of docs considering how common this issue is. Well done on explaining it.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.