script for jump and gravity

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

hi i have problem with my jump and gravity script and i dont know what i doing wrong :frowning:
here is script

extends KinematicBody2D

var gravity = 100
var jumpheight = 100
var velocity = Vector2.ZERO

func _physics_process(delta):
	if Input.is_action_pressed("jump"):
		velocity.y -= jumpheight
		
		velocity.y += gravity * delta
		velocity = move_and_slide(velocity, Vector2.UP)

Edited to fix code formatting…

i have problem with my jump and gravity script

You didn’t describe the problem…

jgodfrey | 2023-02-21 17:47

:bust_in_silhouette: Reply From: exuin

https://forum.godotengine.org/147725/problem-gravity-script-character-shuld-down-stanting-place