0 votes

Whenever my player character lands on the floor, they cannot move. (isonfloor always comes back false for some reason) Heres my player's script:

extends KinematicBody

Initializes Variables

var velocity = Vector3(0,0,0)
const speed = 1
var acc = 1
var gravity = 0.01

Handels Player Physics

func physicsprocess(delta):
velocity.y -= gravity
if Input.iskeypressed(KEYD) and Input.iskeypressed(KEYA):
velocity.x = lerp(velocity.x, 0, 0.1)
elif Input.iskeypressed(KEYD):
velocity.x = min(velocity.x + acc, speed)
elif Input.is
velocity.x = max(velocity.x + -acc, -speed)
velocity.x = lerp(velocity.x, 0, 0.1)
moveandslide(velocity, Vector3.UP)

Any Ideas?

in Engine by (14 points)

1 Answer

0 votes

Change velocity.y -= gravity to velocity.y -= 0 if is_on_floor() else gravity

Also, you should use Input.is_action_pressed rather than Input.is_key_pressed

Look into lerping as well; it is usually better than using min/max

by (731 points)
edited by
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.