-1

My problem is that my character is constantly jumping. How can I prevent this?

Video of my problem: https://www.youtube.com/watch?v=QwmAdzEJH-0

Here is my code(I think this part is wrong):

hitbox = pygame.draw.rect(win, (255, 255, 255), self.hitbox, 1)
first_rect = pygame.draw.rect(win, (0, 0, 0), [385, 465, 117, 75])
second_rect = pygame.draw.rect(win, (0,0,0), [494, 390, 120, 80])
ucuncu_rect = pygame.draw.rect(win, (0,0,0), [596,308,117,84])
dorduncu_rect = pygame.draw.rect(win, (0, 0, 0), [701,240,270,70])
if hitbox.colliderect(first_rect):
   if abs(first_rect.left - hitbox.right) < 10:
      self.x -= 10
   elif abs(first_rect.top - hitbox.bottom) < 10:
      self.y = 314
if hitbox.colliderect(second_rect):
   if abs(second_rect.left - hitbox.right) < 10:
       self.x -= 5
   elif abs(second_rect.top - hitbox.bottom) < 60:
       self.y -= 70
if hitbox.colliderect(ucuncu_rect):
   if abs(ucuncu_rect.left - hitbox.right) < 10:
       self.x -= 5
   elif abs(ucuncu_rect.top - hitbox.bottom) < 55:
       self.y -= 41
if hitbox.colliderect(dorduncu_rect):
   if abs(dorduncu_rect.left - hitbox.right) < 10:
       self.x -= 5
   elif abs(dorduncu_rect.top - hitbox.bottom) < 55:
       self.y -= 35
elif (self.y < 450) and (self.isJump == False):
   self.y += 10
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
  • 3
    You should include the code you've made for jumping I'd say – Rolv Apneseth Feb 23 '21 at 12:57
  • I'm pretty sure this revolves around the fact that upon collision, it shoots the player up into the air, he falls, then it shoots him into the air again, and has nothing to do with jumping itself. I'd say the easiest fix is to not apply gravity if there is something under the character's feet, instead of trying to fight gravity. A similar method could work for the bouncing when trying to run straight into a wall, instead of pushing him back if he's inside, just have a check that makes moves invalid if there is something in the way. This would fix your problems, and make your game much smoother – User 12692182 Feb 23 '21 at 13:49

0 Answers0