0

I think these are the most relevant parts:

def jump(self):
    self.rect.y += 2

    # if we can jump, set our speed up
    if ((len(hits) > 0) or (self.rect.bottom >= WinHeight)):
      self.change_y = -10
def calcgrav(self):
    #does gravity stuff
    if (self.change_y == 0):
      self.change_y = 1
    else: 
      self.change_y += 0.35
    
    #check if on ground
    if ((self.rect.y >= WinHeight- self.rect.height) and (self.change_y >= 0)):
      self.change_y = 0
      self.rect.y = WinHeight - self.rect.height

This is within a class named Player, and it's a pygame sprite. change_y is the change in y of the sprite. Calc_grav() is called within my Player class update function. Hits is a list of collisions with my platforms and sprites. WinHeight is the height of my pygame window.

KauDar123
  • 33
  • 3
  • is it wrong if it works? (not necessarily) – Matiiss Apr 07 '21 at 20:57
  • also I don't see any gravity here, it seems that the player sort of jumps up and then teleports back to ground or sth – Matiiss Apr 07 '21 at 20:58
  • I suggest using mathematical formulas for this for example You could use quadratic equation to calculate the y coords ,btw [here](https://www.youtube.com/watch?v=2-DNswzCkqk&list=PLzMcBGfZo4-lp3jAExUCewBfMx3UZFkh5&index=2) is a tutorial, somewhere along the way a gravity mechanic gets put in the code, so I suggest You really watch it (also more like the whole video is about jumping) – Matiiss Apr 07 '21 at 21:01

0 Answers0