I’m trying to make this little rectangle jump but I cannot come up with a good solution to solve the issue.Theoretically once vely turns negative “gravity” should come into play (- time - is plus) and the box should slide back to its starting position, but this doesn’t happen.Plus, the box shouldn’t move left or right while in the air, but mine does =)
velx = 4
vely = 10
jump = False
keys_pressed = pygame.key.get_pressed()
if jump==False:
'''make rect move form left to right '''
red_rect.x += (keys_pressed[pygame.K_d] - keys_pressed[pygame.K_a]) * velx
if jump == False and keys_pressed[pygame.K_w]:
jump=True
if jump is True:
red_rect.y -= vely
vely-=1
if vely<-10:
jump = False
vely = 10