I am trying to make my Pygame sprite jump so I followed a tutorial and this is what it gave me. But it doesn’t work for some reason. What’s wrong with it
JavaScript
x
14
14
1
keys = pygame.key.get_pressed()
2
if isjump == False:
3
if keys[pygame.K_UP]:
4
if isjump:
5
F =(1 / 2)*m*(v**2)
6
player.rect.y -= F
7
v = v-1
8
if v<0:
9
m =-1
10
if v ==-6:
11
isjump = False
12
v = 5
13
m = 1
14
Advertisement
Answer
You need to set somewher isjump = True
. Additionally the if isjump == False:
needs an else
case:
JavaScript
1
14
14
1
keys = pygame.key.get_pressed()
2
if isjump == False:
3
if keys[pygame.K_UP]:
4
isjump = true
5
v = 5
6
else:
7
m = 1 if v >= 0 else -1
8
F = m * (v**2)
9
player.rect.y -= F
10
11
v -= 1
12
if v == -6:
13
isjump = False
14