0 votes

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 physicsprocess(delta):
velocity.x=Input.getactionstrength("Right")-Input.getactionstrength("Left")
velocity.y=gravity
if(Input.isactionjustpressed("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.

asked Jun 21 in Projects by FireFart (12 points)

1 Answer

+1 vote
answered Jun 21 by deaton64 (1,201 points)

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 :D

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.