fixed movement and added djump

This commit is contained in:
Booklordofthedings 2024-08-16 22:09:19 +02:00
parent bd91fb7117
commit 5e04c4efee
4 changed files with 52 additions and 3 deletions

View file

@ -2,12 +2,36 @@ extends CharacterBody2D
@export var speed = 50
@export var gravity = 50
@export var jump = 700
var max_jumps = 2;
var jumpcount = 2;
var input_direction = 0
func get_input():
var input_direction = Input.get_axis("player_left", "player_right")
var left = Input.is_action_pressed("player_left")
var right = Input.is_action_pressed("player_right")
if left and right:
input_direction = input_direction
elif left:
input_direction = -1
elif right:
input_direction = 1
else :
input_direction = 0
velocity.x = input_direction * speed
if Input.is_action_just_pressed("player_jump") and jumpcount > 0:
velocity.y = -1 *jump
jumpcount = jumpcount-1
elif Input.is_action_pressed("player_jump"):
velocity.y += -1 * 20
func _physics_process(delta):
if is_on_floor():
jumpcount = max_jumps
get_input()
velocity.y += gravity
move_and_slide()