All Questions


Pawel Konopinsky

No lower jump

Hi, hope you can help. This is my code, and so far I can't find any difference to yours, but my player is always jumping up to his maximal jump value no matter how lon i push the buttons (keyboard or controller): extends Actor func _physics_process(delta: float) -> void: var is_jump_interrupted: = Input.is_action_just_pressed("jump") and velocity.y < 0.0 var direction: = get_direction() velocity = calculate_move_velocity(velocity, direction, speed, is_jump_interrupted) velocity = move_and_slide(velocity, FLOOR_NORMAL) func get_direction() -> Vector2: return Vector2( Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), -1.0 if Input.is_action_just_pressed("jump") and is_on_floor() else 0.0 ) func calculate_move_velocity( linear_velocity: Vector2, direction: Vector2, speed: Vector2, is_jump_interrupted: bool ) -> Vector2: var new_velocity: = linear_velocity new_velocity.x = speed.x * direction.x new_velocity.y += gravity * get_physics_process_delta_time() if direction.y == -1.0: new_velocity.y = speed.y * direction.y if is_jump_interrupted: new_velocity.y = 0.0 return new_velocity
  • D
    96dervalics replied

    In your code:

    var is_jump_interrupted: = Input.is_action_just_pressed("jump") and velocity.y < 0.0

    Means that if you press W you will jump, and if you press it again (in mid-air) it cancels the jump.

    If you want to make a small jump, (like in the video) you have to change it to:

    var is_jump_interrupted : bool = Input.is_action_just_released("jump") and _velocity.y < 0.0

    Because you want to cancel the jumping if you release the jump button not when you try to jump again.

    (the bool is not need, but i like to put the type of the variable in my code, you can just write := )

  • Nathan Lovato replied

    Thank you very much for the reply and help. I see this message is from March 7 - I normally reply to everyone, but I missed this one somehow.

    You can write another answer or message me directly if I don't get back to you within a few weekdays - it means I either didn't get or I missed the notification.