#🔒 jumping in a street fighter style game
331 messages · Page 1 of 1 (latest)
@rough pagoda
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
im trying to make my character jump and come back down in my game, i have 6 or 7 sprites for the jump ready as well but im not sure how to create this
Yes
Do I model it the same way?
You have a constant acceleration
When they jump you give them a certain upward speed
And decrease that by the acceleration each frame
Ok thank you I’ll give it a go
Yeah good luck you can always ask about it more as you go
Something pretty small
Bc it happens every frame
What’s the frame rate of your game
Maybe like .02?
I’ve got it as 36
Getting anything to work?
# constatnt gravity
G = 0.2
# changeing velocity
velY = 0
# Current y position
y = 0
if jumping:
velY = 12
# gameLoop
while True:
y -= velY
velY -= G
```I'm pretty sure this works. lemme know
And replace the game loop with your own loop and the if statment with the jump event in your code
Is it also prepering for a jump?
Okay, I guess you can
Like
use the velocity
as the number for the list
index
Like:```py
animList = [0...6]
if velY > 0:
currentImage = animList[int(velY / 2)]
I think this should work?
Can you run this and tell me where I’ve gone wrong please ?
Sure, run what though?
Wait I’ll send the code
Okay
Try it’s exactly how you do it yeah
I don't think you are removing from the velocity the constant gravity
Thank you and I'm sorry I barged in
No problem anyone can help and I was busy for a sec
Okay
I’m removing it in the draw method no?
And yeah I’d pick the sprite based on the velocity
Yeah sorry...
Is there a chance that you are both walking and jumping?
Did you get it to jump without the animation
Don’t think so cause it’s an elif
No
No, I see it
I think
You need to += gravity to velocity instead of -=
I think
I'm not sure
I don't think it's that though
Yh no that didn’t change anything
Maybe i need to change the numbers for the gravity and the other variables?
I dont really, understand?
Lemme see the snippet of the code for the gravity
One sec
Also try to get it without animation
Excuse me if I'm wrong but you're never setting onGround to true?
Oh yhðŸ˜
That shouldn't change anything though
Where would that go?
Yea Yea
But need to sort out the gravity bit first I think cause it’s not actually moving down
Yea I guess
Have you tried decreasing the 12?
I mean, maybe?
Wait it doesn't fall at all?
Nope
First thing I see is you can’t jump while moving left and right
It just goes up and stays there
Bc of if statements
Yeah I’ll change that
Should I put the jump loop at the top?
Like above the left and right
Dude, that's what I said lol
No you should you use multiple if loops
Instead of elif just if
Ok cool
Should the left and right be elifs though?
Cause you can’t go both left and right no?
Alright, sure
but if you are adding to x and then subtracting from x it shouldn't matter
It bugs out when I change any of them to ifs
Oh right okay
Like the animations don’t disappear and they leave like a trail behind the character
Any idea why it’s not going down?
I don't have any, sorry
What’s the issue rn
First we need to figure out the jumping forget about the animations
It will be much easier to add them after
What happens when you jump
The character moves up by like a cm and just stays there
And just keeps going up when I continue to press it
There’s no downward movement
No what should I be checking?
Oh yh that’s meant to be to avoid the player coming off screen but it didn’t really work haha
It’s a bit of a mess haha
Can you help me fix that one first maybe?ðŸ˜
Like to avoid the player from moving too far left and too far right
Okay, Are you sure though?
About what?
That you want to do that first
Yes I need to do it anyway and it seems easier than the whole jump thing
Okay
At the moment when I reach the off screen boundary the character just fully disappears
I get off work in 23 minutes i can help a lot more frequently then sorry
Like:```py
def draw(self):
if not self.x-self.vel>=0 or not self.x+self.vel < screenWidth:
velX = 0
Hold up
Are you like making sure no one sees you help other people?
Lol
And there is a better way of saying that
Im jjust no good english
Did you get it?
It took my character completely off the screen
?
Not exactly
Im not really supposed to be on my phone while working
That's funny
Do I need the ‘ if self.walkCount+1>36 bit
I think
Should it be indented though?
Although you could use mod by 36
Idk how to explain itðŸ˜
Waiting
Yes
So whats wrong with it
Wdym?
Like why’s it not working
I’ve left it as I showed you
Than it shouldn't work
Now the character gets stuck on the boundary
Like it prevents him from going over but it freezes him there
And for some reason the animations for the standing and walking have stopped
Oh sorry,
My bad
it should be just X
x
small x
instead of velX
Could you repaste your code?
Does it give you any errors?
if not self.x-self.vel>0:
self.x=1
if not self.x+self.vel<SCREEN_WIDTH:
self.x = SCREEN_WIDTH
No but it makes my character freeze on the border
This should work
And the animations mess up
Okay
That was an overlook on my side
He just goes through the right side and starts at the left side
I updated the code
Did you guys get the borders figured out
I think so
The boundary is a bit too far on the right side I’m trying to fix it
Oh right that would be do to the fact that we are subtracting from the total width instead of adding or the other way around I think
Well I can help now so lmk if there’s an issue
I should set x equal to that?
^
Probably
Ok think ive got it
minus one I think
I dont know why the animations have gone all weird though
Ok yh perfect the barriers work
Now jumping?
Oh i bet i know why jumping didnt work
Not yet cause the animations are still bugging
O, do feel free to share
Bugging how?
You are setting self.jump to false as soon as it is true
The animations arent like moving like before
Even when hes still he should have an animation for standing but when i set them barriers its just stopped all of that
So i should take out the self.Jump= false from the end of the draw method?
No
I would
No why?
You only want self.jump to be false once the character gets back to the floor
Yeah so why put it at the end?
I said to not put it at the end
No?
Do you want your chracter to start on the ground?
BTW the vel variable and the gravity var, does each chrarcter needs one of his own?
I mean
can't they be outside the class?
No every characters gonna have the same
Oh yhðŸ˜
Ok so now the character does go down but he goes through the floor
Progress !!🤣
Lol
But he’s also going really high up
Like off the screen high and then coming back down really slow
Ok cool
Oh and you can also change the gravity
Lower or higher?
The gravity heigher, the "jumpStreangth" if you will lower
Ok nice it’s better now I think
I can’t really tell how high it’s going cause it goes invisible
How do you mean?
But when I crouch or move side to side I can see where abouts it is
See if i dont press crouch its just invisible
Interesting
I think I know why
in the jump state you are not window.blit ing the chracter
And then what do i put inside the []
Ok ill give it a go
Wdum?
Yeah
Why?
Also for the jump surely it shouldn’t just be one set number in the [] cause it’s 6 different sprite images
Idk, it's very late out here
Yaeh so a variable is the best option?
Sorry broðŸ˜
Wdym?
For taking up your time with this shit haha
Nah it fine
Can you show me what you mean by this
Okay
self.jumpCount = 0
# seperate piece of code AKA: draw method
elif self.jumping:
image = jumping[jumpCout]
if jumpCount < 6:
jumpCount += 1
I think this should do it
I think ima go
Good night
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.