+2 votes

Hi, I am new to Godot , its been 9 days and I have been really enjoying developing in this game engine. :-)

i am working on a platformer, i want the player to automatically jump when it lands on a specific object.

I guess i need a script to automate jump function with an if statement,

Can somebody help me out with this? I would appreciate help!

Thanks!

in Engine by (17 points)

1 Answer

0 votes
Best answer

Presumably you have some piece of player code that initiates a jump when the player presses the right button:

if Input.is_action_just_pressed("jump"):
  ...perform jump...

You can change this to something like this:

var make_player_jump := false

if Input.is_action_just_pressed("jump") or make_player_jump:
  make_player_jump = false
  ...perform jump...

Then simply set make_player_jump = true when a collision is detected between the player and the specific object, and the player will be forced to jump on the next frame.

by (268 points)
selected by

thanks a lot for that one :)

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.