Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Do any of you guys know how to code a double-jump?

A topic by Kasper Hviid created 69 days ago Views: 65 Replies: 3
Viewing posts 1 to 3
Submitted

I know I can trigger the normal jump with $Player/Body.request_jump() but I don't really know how to do the second double-jump. Anyone have any experience here?

Jam HostSubmitted

The standard implementation of jump in the PlayerBody does not support double-jump. It was written to try and emulate physically real behavior.

You may need to hack the function to take a second "allow-if-not-on-ground" argument defaulted to false, but with the ability for you to manually call to trigger a second in-air jump.

You may wish to put in a feature-request into the Godot-XR-Tools github ticket system.

Submitted (1 edit)

Not sure what build you're in, but for the latest and greatest of the moment, G 4.2.2 and XR Tools 4.3.3, 

within the player_body.gd: request_jump() call, line 347;

## Request a jump
func request_jump(skip_jump_velocity := false):
    # Skip if not on ground
    if !on_ground: <--------
        return

is the what stops the jumping so change the if statement into the one below
and you'll need to create a var jump_counter : int = 0 
The int may help save some headaches , and the = 0 is needed.     

    if jump_counter < 2:
         jump_counter += 1
     else:
         return

On line 352; this pops up and may lead to issues if in air, 

    if abs(ground_relative.dot(ground_vector)) > 0.01:          


To reset the counter, we go into line 616, in  

func _update_ground_information(delta: float):

on line 631, after the 

if !ground_collision:
         near_ground = false
         on_ground = false
         ground_vector = up_gravity
         ground_angle = 0.0
         ground_node = null
         ground_physics = null
         _previous_ground_node = null
         return

statement, you can add the 

jump_counter = 0

to reset everything back to normal.


sorry for the messy text but I'm still getting the coffee flowing in me

Submitted(+1)

Thanks! My game is still a mess, but now it's a mess with double-jump.