Why Won't My Character Jump In Pygame/python
This is my first Pygame game that I'm making. I am planning on making a 2 player fighting game with basic squares/blocks. I am now trying to implement jumping into the first charac
Solution 1:
When you press w to jump, the game will change the value of y_change
to -5
as intended. When the event queue has been processed, it goes on to this block:
if y <= 480:
onGround = False
else:
onGround = True
if onGround == False:
y_change = 5
if onGround == True:
y_change = 0
Your physics has not been simulated yet at this point, so your character is still on the ground. In other words, onGround
is still True
. Therefore, the if onGround == True: y_change = 0
code gets executed, and y_change
is set back to 0 again.
After this has happened, your physics simulation happens, and y_change
is now 0. This is why your character does not jump. You need to redesign your code so that the game realizes that your character is starting to jump when it's checking whether he's on the ground or not. Good luck with your game!
Post a Comment for "Why Won't My Character Jump In Pygame/python"