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.
Graphics 640,480

y# = 400
yvel#=0
gravity# = .1
groundlevel = 400

Repeat
Cls

; draw the ground
Color 0,100,0
Line 0,401,320,401
Line 320,301,320,401
Line 320,301,639,301


Color 255,255,255

Text 320,0,"Press SPACE to jump, ESC to exit",True

For x=0 To 639
	y=y+yvel
	yvel = yvel + gravity
	
	; change of floor level
	If x<320 Then groundlevel = 400 Else groundlevel = 300
	
	; hit the ground
	If y > groundlevel Then
		y = groundlevel
		yvel = - yvel * .2 ; bounce
	EndIf
	
	Plot x,y
	
	If KeyHit(57) Then yvel#=-5
	
	Delay 10
	
	If KeyHit(1) Then End
Next

Forever



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