![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | PopSquip |
my movement code is not replenishing jumps when it touches a tilemap how should i fix this? code is below:
extends KinematicBody2D
const GRAVITY = 10 # in pixels
const JUMP = 250 # start speed px/s
const SPEED = 200 # px/s
var velocity = Vector2.ZERO # (0,0)
var jumps_available := 2
func _ready():
pass
func _on_Timer_timeout():
print(str($Timer.wait_time) + " second(s) finished")
func _physics_process(delta):
# if no keyboard input for left/right then x speed is 0
velocity.x = 0
if(Input.is_action_pressed("right")):
velocity.x = SPEED
elif(Input.is_action_pressed("left")):
velocity.x = -SPEED
velocity.y += GRAVITY
# _physics_process
if Input.is_action_just_pressed("jump") and jumps_available > 0:
velocity.y -= 250
jumps_available -= 1
# _physics_process
if is_on_floor():
jumps_available = 2
velocity = move_and_slide(velocity)
how can i fix this?