![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Zandereal |
I can’t figure out how to jump while I am moving but I can’t figure out how. Here is the code,
extends KinematicBody2D
const GRAVITY = 300.0
const WALK_SPEED = 500.0
var velocity: Vector2 = Vector2.ZERO
func _physics_process(delta):
velocity.y += delta * GRAVITY
if Input.is_action_pressed("left"):
velocity.x = -WALK_SPEED
elif Input.is_action_pressed("right"):
velocity.x = WALK_SPEED
elif Input.is_action_just_pressed("jump"):
velocity.y = -WALK_SPEED
else:
velocity.x = 0
# "move_and_slide" already takes delta time into account.
move_and_slide(velocity)