0 votes

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?

Godot version 3.3.3
in Engine by (37 points)

I don't see any code relating to touching a tilemap or touching anything.

is there a way i can make it work?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.