+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!


asked Apr 15 in Engine by A Godot Learner (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.

answered Apr 16 by caprinae (264 points)
selected Apr 27 by A Godot Learner

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 How to use this Q&A? before posting your first questions.