2
\$\begingroup\$

This is an extremely simple game (following tutorial).

My code and configuration allows the actor object to fall on a platform made of tilemaps and not fall through, but the function is_on_floor() always outputs false.

extends KinematicBody2D
class_name Actor

var velocity: = Vector2.ZERO;
export var gravity: = 3000.0;

func _physics_process(delta):
    velocity.y+=delta*gravity;

    velocity = move_and_slide(velocity);
    if is_on_floor():
        print_debug("on floor");
    else:
        print_debug("not on floor"); #only this line prints

What's going on? Is the is_on_floor() function usable or do I need to use an alternative way of floor-detection?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

If you call move_and_slide with only one parameter, all collisions are considered walls. This is useful in top down games.

You need to specify an up vector which Godot will use to decide if the collision is a wall, a floor or a ceiling.

For example, like this:

velocity = move_and_slide(velocity, Vector2.UP)
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .