How to prevent KinematicBody2D from teleporting when jumping?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WaterDeveloper

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!

:bust_in_silhouette: Reply From: timothybrentwood

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.

Thanks alot! i didn’t know move_and_slide did that automatically, that’s new
thanks alot!

WaterDeveloper | 2021-05-13 02:00