This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So I'm relatively new to Godot, and I just tried making my first 2.5D game. I want to implement gravity, but the "isonfloor" function is always reporting false, so the player never stops falling. (It just falls through the floor) Both the player and the Floor have collision. I've been messing with this for several hours now! Here's my player script:

extends KinematicBody

var velocity = Vector3(0,0,0)
var SPEED = 1
var accel = 0.1
var gravity = 0.1
var jump = 0

func physicsprocess(delta):
if not isonfloor():
velocity.y -= gravity
if Input.iskeypressed(KEYD) and Input.iskeypressed(KEYA):
velocity.x = 0
elif Input.iskeypressed(KEYD):
velocity.x = min(velocity.x + accel, SPEED)
velocity.x = max(velocity.x - accel, -SPEED)
velocity.x = lerp(velocity.x, 0, 0.1)

if Input.is_key_pressed(KEY_W) and Input.is_key_pressed(KEY_S):
elif Input.is_key_pressed(KEY_S):
elif Input.is_key_pressed(KEY_W):
    #velocity.z = lerp(velocity.z, 0, 0.1)
if not Input.is_key_pressed(KEY_W) and not Input.is_key_pressed(KEY_A) and not Input.is_key_pressed(KEY_S) and not Input.is_key_pressed(KEY_D):

btw, I haven't used the jump variable yet. Cant jump it you just fall through the floor!!! If someone can understand what the problem is or needs further info, please reply! Any help is much appreciated! Have a nice day.


in Engine by (14 points)
edited by

1 Answer

0 votes

Hey Fired,

you have to specify the up_direction:

move_and_slide(velocity, Vector3.UP)

"up_direction is the up direction, used to determine what is a wall
and what is a floor or a ceiling."

by (1,081 points)

I put moveandslide(velocity, Vector3.UP) after the line with "velocity.y -= gravity", and it didn't change anything.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.