Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PopSquip |
i am making a 2d fighting game and the movement code isnt replenishing jumps when the player touches the tilemap my 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 jump_cooldown_time = 1000
var next_jump_time = 0
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
if (Input.is_action_just_pressed("jump")):
# Check if player can jump
var now = OS.get_ticks_msec()
if now >= next_jump_time:
velocity.y -= 250
#add cooldown time for jump
next_jump_time = now + jump_cooldown_time
velocity = move_and_slide(velocity)
how do i fix this?
I don’t see any code relating to touching a tilemap or touching anything.
exuin | 2021-09-10 18:41
is there a way i can make it work?
PopSquip | 2021-09-11 03:18