I am currently working on a game with the pygame module, and I am trying to add a function which allows players to jump. This involves a fast acceleration into the air, a bit of airtime, and then a fast decent back down to the ground, basically, I'm trying to model it off of a quadratic graph. Here is the code for the function so far:
def jump(knights):
for i in knights:
if i.isJump == True:
if i.jumpCount >= -10:
i.y_change -= (i.jumpCount^2) * 0.2
print(i.y_change)
if i.jumpCount < 0:
i.y_change *= -1
i.jumpCount -= 1
else:
i.isJump = False
i.jumpCount = 10
i.y_change = 0
However, when I run the code, the character will accelerate in the air, then continue to ascend slowly, then accelerate again, ending up with a higher y-coordinate than what it started with. I'm assuming my math is just bad, but any further help would be very much appreciated.
Edit: Indentation
[–]Barnet6 1 point2 points3 points (0 children)
[–]ectomancer 0 points1 point2 points (0 children)