All Questions


Arthur Honorio do Carmo
posted to: Creating the Enemy

Error when releasing the jump button in mid jump

I got an error message when I released the jump button before the completion of the jump while holding left or right button, so I tried and changed the _out.y of the player's script in the if is_jump_interrupted condition from _out.y = Vector2.ZERO to _out.y = gravity * get_physics_process_delta_time( ) and it seems to have solved the problem. Is this ok? Is anyone else getting this error message?

  • Nathan Lovato replied

    Could you copy and paste your code here?

    You can format it as code using the "magic wand" drop-down icon and using the "Code" style.

    Like so
  • Arthur Honorio do Carmo replied

    Sorry about the delay on answering you, I didn't know you had answered.
    This is the one getting an error:

    func calculate_move_velocity(
    linear_velocity: Vector2,
    direction: Vector2,
    speed: Vector2,
    is_jump_interrupted: bool
    ) -> Vector2:
    var out = linear_velocity
    out.x = speed.x * direction.x
    out.y += gravity * get_physics_process_delta_time()
    if direction.y == -1.0:
    out.y = direction.y * speed.y
    if is_jump_interrupted:
    out.y = Vector2.ZERO
    return out

    this is the error it returns, after stopping and closing the game.

    I resolved by changing:

    if is_jump_interrupted:
    out.y = Vector2.ZERO


    if is_jump_interrupted:
    out.y = gravity * get_physics_process_delta_time()
  • Nathan Lovato replied

    The error is normal, you're trying to assign a whole Vector2 to the Y component of your "out" vector. In other words, you're trying to assign a Vector2 value to a property of type float.

    You need to remove the ".y" to fix it:

    out = Vector2.ZERO