0 votes

Hello, I'm creating a topdown game and I want to use a Jump state, but idk how to do it in code. Atm I have this:

Simple right-left movement

mover = Vector2.ZERO
    if Input.is_action_pressed("direita"): #right
        mover.x += 1
    if Input.is_action_pressed("esquerda"): #left
        mover.x -= 1
    mover = mover.normalized() * speed
    if Input.is_action_just_pressed("pular"): #jump button
        _pular()

And my jump function:

set_collision_mask_bit(2,false)
mover.y = mover.y - 10
 set_collision_mask_bit(2,true)

And my physicsprocess:

movimentar()
mover = move_and_slide(mover)

I tried too using an AnimationPlayer, but cant set the position.y to the actual position in the game.
What I want its the player moving like 10-15 pixels up and then back to the original position.

in Engine by (171 points)

1 Answer

0 votes

Create a timer and set its tim how much time you want your character on air.
Jump function:
#something like this#
$timer.start()
setcollisionmask_bit(2,false)
mover.y = mover.y - 10

When timer times out:
setcollisionmask_bit(2,true)
mover.y = mover.y +10

Hope this can help

by (14 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 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 webmaster@godotengine.org with your username.