0 votes

So,i have a player(kinematicBody) is a sphere.
And i have an area,with his collision shape,mesh and also a static body(cuz i don't want it to fall)

And i also have a script,if i press UP the player jumps,with a cooldown,

What i want is:
if the player press jump key cooldown is on,and it will reset to off when the player touches the ground after jumping.

Player Script:

    extends KinematicBody

    var velocidad = 100 #speed
    var gravedad = -9.8 #gravity
    var CDsalto = false #cooldown

   func _physics_process(delta):

var impulso = Vector3(0,0,0) #impulse
var dir = Vector3(0,0,0)#Direction

#Salto - jump
if (Input.is_action_pressed("ui_up") and CDsalto == false):
    impulso.y += 100
    CDsalto = true

#Gravedad - gravity
impulso.y += gravedad

#Aplicar Salto - apply jump
dir = impulso * velocidad
move_and_slide(dir * delta)

    #Suelo is ground in spanish
    func _on_Suelo_area_entered(area):
CDsalto = false

Screenshots:
Main Scene
Ground Scene
Player Scene

in Engine by (108 points)

1 Answer

0 votes

Use This Code

extends KinematicBody
var velocidad = 100 #speed
var gravedad = -9.8 #gravity
func _physics_process(delta):
    var impulso = Vector3(0,0,0) #impulse
    var dir = Vector3(0,0,0)#Direction
    if is_on_floor():
        if (Input.is_action_pressed("ui_up")):
            impulso.y += 100
    impulso.y += gravedad
    dir = impulso * velocidad
    move_and_slide(dir * delta)
by (28 points)
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.