Jumping

Blitz3D Forums/Blitz3D Beginners Area/Jumping

W(Posted 2006) [#1]
Hey guys, is there any way that someone can demonstrate how to perform a decent looking jump? right now I am attempting to use a few timers and inbetween I am using the TranslateEntity function to move the character up. Any help or suggestions would be appreciated!!

/thanks\\


jfk EO-11110(Posted 2006) [#2]
since jumping is body force that acts against gravity for some time, you could add it to the gravity (eg. using a curve stored in an array). I would suggest to add some kind of bending of the body before jumping, plus the same when back on the ground.

and most important add the "hmpf!" sound :)


W(Posted 2006) [#3]
lol...true that I got ya JFK thanks man


octothorpe(Posted 2006) [#4]
A curve stored in an array? That's revolting.

This is a simple physics problem. Keep track of the velocity of your characters. Every frame, add gravity to each character's velocity. When they jump, subtract the acceleration of the jump (try different values to get the height you want) from the velocity. The character will automatically follow a realistic parabolic curve.


Pongo(Posted 2006) [#5]
here is a simple 2d example, You didn't say 2d or 3d, but the same code would work for both.

This would also need a timer so you would not be able to continuously jump.

Graphics 640,480,0,2
SetBuffer BackBuffer()

gravity# = 1 ; set strength of gravity

;set initial position and velocities
playerXpos# = 320
playerYpos# = 240
playerXVel# = 0
PlayerYVel# = 0

While Not KeyHit (1)
	;get player Input
	playerXvel =  playerXvel -(KeyDown(203)-KeyDown(205)) ; add user movement to the X velocity
	playerYvel = playerYvel + gravity ; add gravity to the Y velocity
	If KeyHit(57) playerYvel = -20 ; if the space bar is hit, then jump

	;add velocities to the current positions
	playerXpos = playerXpos + PlayerXvel
	playerYpos = playerYpos +PlayerYvel

	; bounds checking
	If playerYpos > 400 playerYpos = 400 	;ground plane
	If playerxpos < 0 playerXpos = 0			;left edge
	If playerxpos > 630 playerXpos = 630	;right edge

	;draw the screen
	Rect playerXpos,playerYpos,10,10  ; draw the player
	Line 0,410,640,410 ; draw the ground
	Text 0,0," use left/right arrows to move, space to jump"

	playerXvel = playerXvel * .9 ; create drag for the X movement
	
	Flip
	Cls 
Wend




n8r2k(Posted 2006) [#6]
or instead of a timer you could check to see if the players y velocity is changing. If it is then dont allow the player to jump again.


n8r2k(Posted 2006) [#7]
or instead of a timer you could check to see if the players y velocity is changing. If it is then dont allow the player to jump again.


Sir Gak(Posted 2006) [#8]
n8r2k
RE: Your new quote, as seen by an American.

Logically, an "evil twin" (wherein "evil" is a moral quality, not "opposite of") implies a "good twin" if no other moral assessment is otherwise explicitly made for the twin in question. (I have two younger brothers who are twins!). However, if the other twin in question is explicitly specified also as evil, then it just means BOTH are evil. Sorta like the OR logic command.

a=1 :evil twin
b=0 :good twin
a OR b = 1

a=1 ;evil twin
b=1 :evil twin
a OR b = 1

Remember folks, you heard it here on Blitz!