How to automate jump when the character lands on a specific object?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By A Godot Learner

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

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!

:bust_in_silhouette: Reply From: caprinae

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.

thanks a lot for that one :slight_smile:

A Godot Learner | 2020-04-27 08:03