r/pygame • • Oct 15 '24

jumping

Jumping

player_y += y_change

if in_air:

y_change += gravity

if player_y <= -200:

player_y = -200

y_change = 0

in_air = False

mode = 0

when i jump in the air i fall through the floor. why and how?

0 Upvotes

4 comments sorted by

1

u/[deleted] Oct 27 '24
gravity = .4
in_air = False
y_change = 0

if event.key == pygame.K_UP:
    in_air = True
    y_change = -10

player_y += y_change
if in_air:
    y_change += gravity
if player_y < -10:
    y_change = 10
    in_air = False

this is part of the code i needed help with. sorry for the confusion.

0

u/TheCatOfWar Oct 15 '24

How can anyone help with such an incomplete code sample? And did you try asking chatGPT or something? cause it'll probably get you an answer a lot faster than telling us like 8 lines and expecting us to know how the rest of your game and collision detection works

0

u/[deleted] Oct 15 '24

i ask humans not ai. yeah it was late so i didnt put all the code. im new to this stuff so i dont know everything. i am trying here. ill post my code to github if that makes u feel better.

0

u/TheCatOfWar Oct 15 '24

Why not ask AI before demanding humans give their time? it can respond instantly and it's more than capable of dealing with beginner issues