Struggling to jump

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

So i am new to this gdscript, and struggled to code a jump, this is my attempt

extends KinematicBody2D

var velocity := Vector2.ZERO
export var speed := 400.0
export var gravity := 1.0
export var jumppower := 40.0

func _ready():
pass # Replace with function body.

func _physics_process(delta):
velocity.x=Input.get_action_strength(“Right”)-Input.get_action_strength(“Left”)
velocity.y=gravity
if(Input.is_action_just_pressed(“Jump”)):
velocity.y-=jumppower
if(velocity.y<1.0):
velocity.y+=gravity
velocity= velocity*speed
move_and_slide(velocity)

I want an ordinary jump, but instead the script makes it teleport upwards then fall ordinarily. Are there any tips for fixing this issue? Thanks in advance, and sorry if my code is quite a mess.

:bust_in_silhouette: Reply From: deaton64

Hi,
Take a look at this: https://kidscancode.org/godot_recipes/2d/platform_character/

That really helped, thanks for that. But i prefer reasons why my code dont work cuz i want to understand how it works. Still, thanks a lot for the help :smiley:

FireFart | 2020-06-22 18:56