now i need some help with my jump timer
Blitz3D Forums/Blitz3D Beginners Area/now i need some help with my jump timer
| ||
ok it will go up ok and stop when the Millisecs() >= jumptime but i can't get it to come back down...it all looks ok to me but i guess it's not If KeyHit(57) jumptime = MilliSecs() + 2000 If MilliSecs() < jumptime yvel# = yvel# + 2 If MilliSecs() >= jumptime yvel# = yvel# - 2 If yvel# = 0 yvel# = 0 EndIf EndIf EndIf EndIf |
| ||
hrrrm well don't use equal then or greater to jumptime, i don't see any need to worry about a millisec or two. Your only checking jumptime if the jump key is hit btw. use this: If keyhit(57)= true then jumptime=millisecs()+2000 yvel#=yvel#+2 endif If jumptime <>0 then If millisecs()>jumptime yvel#=yvel#-2 jumptime=0 endif p.s. I use stance or position and duration for these kind of things. Depending on how complicated your program gets it may become useful, good luck. Like this: global standing=0 global walking=1 global jumping=2 ;MAIN LOOP dur=dur-1 If keyhit(57)=true then stance=jumping dur=10 yvel#=yvel#+2 endif If stance=jumping then If dur<=0 stance=standing yvel#=yvel$-2 If yvel#<=0 yvel#=0 endif |
| ||
i'll ave a search from one of my old 3d platformer demo codes, i found it pretty easy to do iirc. |
| ||
Um... If you're using a Yvel# why aren't you just applying a gravity to it? ie. |
| ||
First of all, your EndIf's are in the wrong places. If Millisecs() >= jumptime will never be true because you only check it if Millisecs < jumptime. Don't know if this will work in your program, but this is how it probably should look.If KeyHit(57) And jumpflag = False ;define jumpflag = False somewhere before main loop jumptime = MilliSecs() + 2000 jumpflag = True EndIf If jumpflag = True If MilliSecs() < jumptime yvel# = yvel# + 2 EndIf If MilliSecs() >= jumptime yvel# = yvel# - 2 If yvel# < 0 yvel# = 0 jumpflag = False EndIf EndIf EndIf |
| ||
ok coming back down isn't my problem anymore now i just need to be able to move up constantly if spacebar is hit not held down because it screwed up when i added the gravity(which wasn't as hard as i thought) |
| ||
i got it now...hopefully i won't have to post any more forums up for a little bit |
| ||
How'd you end up doing it? I've never been able to figure out jumping.... |
| ||
i put this in the main loop to do the gravity; start the falling process If falling = True yvel# = yvel# - .3 If yvel# <= 0 yvel# = 0 falling = False EndIf EndIf and i put this where i checked for the keys ; press spacebar to jump If KeyHit(57) And jumped = False And falling = False jumped = True EndIf If jumped = True yvel# = yvel# + .3 ; if the player is at highest point, start moving down If yvel# >= 5 falling = True jumped = False EndIf EndIf |