0 votes

So when I add "and isonfloor()" it makes the jump function not work at all, but it works before I add the "isonfloor()", I have the floor defined with velocity = moveandslide(velocity, Vector2.UP) so idk, any help? Here's my code;

extends KinematicBody2D

var velocity = Vector2(0,0)

const Speed = 200
const Jumpforce = -900
const Gravity = 30

func _physics_process(delta):
    if Input.is_action_pressed("right"):
        velocity.x = Speed
    if Input.is_action_pressed("left"):
        velocity.x = -Speed
    move_and_slide(velocity)

    velocity.y = velocity.y + Gravity

    if Input.is_action_just_pressed("Jump") and is_on_floor():    
        velocity.y = Jumpforce

    velocity = move_and_slide(velocity, Vector2.UP)

    velocity.x = lerp (velocity.x,0,0.2)
Godot version 3.3.3
in Engine by (16 points)
edited by

Are you aware that "jumpforce" is set to a negative number?

1 Answer

0 votes

Remove the first move_and_slide

by (1,448 points)
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.
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.