Im new to programming as well as Godots GD Script.
The Jump movement works however, the character only jumps and doesnt move right/left in mid air. Also I cant Jump while im holding down right/left button.
This is the basic movement code for my character. The game is pretty simple, a platformer.
The Jump code is marked with **
extends KinematicBody2D
const GRAVITY = 15
const ACCELERATION = 20
const MAX_SPEED = 30
const JUMP_FORCE = 150
const FLOOR = Vector2(0,-1)
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
var walk = $PlayerWalkSound
var isWalking = false
if Input.is_action_pressed("ui_right"):
isWalking = true
motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("Walk")
if not $PlayerWalkSound.is_playing():
$PlayerWalkSound.play()
elif Input.is_action_pressed("ui_left"):
isWalking = true
motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("Walk")
if not $PlayerWalkSound.is_playing():
$PlayerWalkSound.play()
**elif Input.is_action_just_pressed("ui_up") and is_on_floor():
motion.y = - JUMP_FORCE**
else:
isWalking = false
motion.x = 0
walk.stop()
$AnimatedSprite.play("Idle")
motion = move_and_slide(motion, FLOOR)