+2 votes

Hello, I'm a kind-of-beginner to godot 3 (I have some experience) and I have noticed that when I put moveandslide(velocity, FLOOR) (FLOOR is Vector2(0, -1) and velocity is my movement) inside of a kinematicbody2D script, If the player walks against the kinematicbody2D, it will start moving constantly by just a tiny bit, and if the player tries to walk on top of it, after being on the kinematicbody2D for a little bit the object just falls right through! My game pretty much relies walking on kinematicbody2Ds to work, so am I doing something wrong with moveandslide, or is it just a glitch in the engine?


in Engine by (18 points)

Could You parse code sample of how do You handle input and movement ?

yes I can but I don't have access to my PC right now, but I will later today
I'll do it as soon as I can

if Input.isactionpressed("ui_right"):
$CollisionPolygon2D.scale = Vector2(1, 1)

    $AnimatedSprite.flip_h = false
    if on_ground == true:
        vel.x = min(vel.x + acc, regSpeed)
        vel.x = min(vel.x + acc - 3, regSpeed)

elif Input.is_action_pressed("ui_left"):
    $CollisionPolygon2D.scale = Vector2(-1, 1)
    $AnimatedSprite.flip_h = true

    if on_ground == true:
        vel.x = max(vel.x + -acc, -regSpeed)
        vel.x = max(vel.x + -acc + 3, -regSpeed)

    vel.x = lerp(vel.x, 0 , 0.2)

if on_ground == true:

    gravity = 10
    idle = "idle"
    $AnimatedSprite.offset = Vector2(0, 0)

#jump code

#regular jump
if Input.is_action_pressed("jump"):
    if on_ground == true:
#if player releases jump key before max jump is reached, start falling
if Input.is_action_just_released("jump"):

vel.y = min(vel.y + gravity, 350) #makes the player fall with gravity

vel = move_and_slide(vel, FLOOR) #makes the player move with coded physics

and the movement for the non-player kinematicBody2D is:

extends KinematicBody2D
var gravity = 10
var vel = Vector2()
var FLOOR = Vector2(0, -1)

func physicsprocess(delta):
vel = moveandslide(vel, FLOOR)
vel.y += gravity

Please log in or register to answer this question.

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 webmaster@godotengine.org with your username.