physiks jump

Blitz3D Forums/Blitz3D Programming/physiks jump

stanrol(Posted 2012) [#1]
s=1
x=1
While 1
 ;Delay(50)
 Cls
 Plot(x Mod 111, 70*Cos(s)+166)
 s=s+1
 x=x+1
 Flip
Wend


how do i jump dot?


Midimaster(Posted 2012) [#2]
jumping consist from two elements: the energy of the jumper, which rises the figur and the gravity, which brings him back to earth:

1st step: free fall:
Graphics 800,600
SetBuffer BackBuffer()

BallY#=100
SpeedY#=0
Gravi#=0.1

Repeat
	Cls

	SpeedY=SpeedY+Gravi
	BallY = BallY+SpeedY
	
	Oval 400, BallY,11,11
	Flip 1
Until KeyHit(1)


The gravitation Gravi# affects not direct on the position of the object, but on its falling speed SpeedY#. The falling speed SpeedY# becomes permantent higher:

SpeedY=SpeedY+Gravi




This speed changes the position of the object:

BallY = BallY+SpeedY




in case of jumping a object puts a lot of (negativ) energy into the SpeedY. This results in rising up. The gravity imediately reduces the speed, so that the rising slows down, comes to an end and turn backward to earth:

Graphics 800,600
SetBuffer BackBuffer()

BallY#=100
SpeedY#=0
Gravi#=0.1
BodenY#=400
FPS=CreateTimer(60)
Repeat
	Cls
	Text 100,100,"Press 1 to jump"
	SpeedY=SpeedY+Gravi
	BallY = BallY+SpeedY
	
	If BallY>BodenY Then
		SpeedY=0
		; if it would be a ball, the energy would turn:
		;SpeedY = -SpeedY *0.8

		BallY=BodenY
	EndIf
	If KeyHit(2)
		SpeedY=-8
	EndIf	
	Oval 400, BallY-11,11,11
	Line 0,BodenY,800,BodenY
	Flip 0
	WaitTimer fps
Until KeyHit(1)


If BallY# touches the floor BodenY#, the speed is set to 0. When you again press key "1" the speed is set to "-5", what means "up-to-the-sky".