0 votes

hey yall,
I've been working on projects around the year and i stumbled on this error for all of them.
the KinematicBody2D i use doesn't jump normally and just teleports in air.
here's my code:

extends KinematicBody2D

var max_speed = 7000
var velocity = Vector2.ZERO

func _physics_process(delta):
    if Input.is_action_pressed("ui_right"):
        velocity.x = max_speed
    elif Input.is_action_pressed("ui_left"):
        velocity.x = -max_speed
    else:
        velocity.x = 0
    if Input.is_action_just_pressed("ui_up"):
        velocity.y += -45000

    velocity.y += 10000

    velocity = move_and_slide(velocity * delta)

It's worth mentioning that this case only happens when using delta, Which I like to use to keep things fair.
thanks in advance for all the answers!

in Engine by (15 points)

1 Answer

0 votes
Best answer

move_and_slide(velocity * delta)
move_and_slide() incorporates delta automatically so you should remove delta from there.

Your character teleports because: velocity.y += -45000 that's a massive amount of upwards force. Try changing it to -450 and see if that's better.

by (3,545 points)
selected by

Thanks alot! i didn't know moveandslide did that automatically, that's new
thanks alot!

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.