This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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.

in Engine by (12 points)

1 Answer

+1 vote
by (2,065 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 Frequently asked questions and 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 [email protected] with your username.