How do I make my Pygame Sprite jump higher and farther?

Question:

I am making a game in Pygame and this is my code to jump:

keys = pygame.key.get_pressed()
if isjump == False:
    #Up arrow key
    if keys[pygame.K_UP]:
        isjump = True
        v = 5
else:
    m = 1 if v >= 0 else -1
    F = m * (v**2)
    player.rect.y -= F

    v -= 1
    if v == -6:
        isjump = False

I want it to jump farther and higher. How can I do it?

Asked By: Pixeled

||

Answers:

The height of the jump depends on v. Define a variabel (jump_v) for the initial value of v. Use a higher value than 5, for a higher jump:

jump_v = 7 # try different values

keys = pygame.key.get_pressed()
if isjump == False:
    #Up arrow key
    if keys[pygame.K_UP]:
        isjump = True    
        v = jump_v              # <--- jump_v 
else:
    m = 1 if v >= 0 else -1
    F = m * (v**2)
    player.rect.y -= F
    
    v -= 1
    if v < -jump_v:             # <--- jump_v 
        isjump = False
Answered By: Rabbid76
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.