Problem with SMOOTH 3D Jumps?

Blitz3D Forums/Blitz3D Programming/Problem with SMOOTH 3D Jumps?

Guy Fawkes(Posted 2012) [#1]
Hi all, can someone make it so that as soon as the user presses the spacekey, the player SLOWLY and SMOOTHLY ascends upward, then when the player reaches a certain height, make him SLOWLY fall back down to earth, both increasing the amount of speed when jumping, and the decreasing the amount of speed when falling, as opposed to taking off like a NASA rocket, and never returning to earth? O.O



Here's the code:







Thanks for any / all help! :)


Rroff(Posted 2012) [#2]
tbh you'd be better off looking at a physics library once you start any serious object movement.

Or alternatively look at the castle sample code in the included examples with B3D as that has jump code in there.


Guy Fawkes(Posted 2012) [#3]
Well is there an easier way to simulate a moon jump? That's all I acquire :)


RifRaf(Posted 2012) [#4]
Edit:
heres another sample in code archives that can get moon type gravity just by changing the gravity value.. please do your SOME research before putting your hands out.

http://www.blitzbasic.com/codearcs/codearcs.php?code=365

Last edited 2012


Midimaster(Posted 2012) [#5]
Thundros, you forgot to add gravitiy also when rising up the player. The gravity always exists! In case of falling it makes the player falling faster and faster. In case of jumping it make the player moving slower and slower upto the point, when the direction turn to downwards...
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()
SeedRnd MilliSecs()


;die Kamera
	Global Cam1=CreateCamera()
		MoveEntity Cam1,10,5,-15
		CameraFogMode cam1,1
		CameraFogColor Cam1,255,255,255
		CameraFogRange Cam1,1,300
;World
	Boden=CreatePlane()
		EntityColor boden,15,115,15
	Himmel=CreateSphere(32)
		FlipMesh himmel
		ScaleEntity Himmel,800,99,800
		EntityColor himmel,0,0,255
;Licht:
	Licht=CreateLight()
		TurnEntity licht, 0,90,0
		MoveEntity licht,-30,30,30

		MoveEntity himmel,0,0,00



Global type_player 	= 1
Global type_land 	= 2
Global type_obj 	= 3



Collisions type_player, type_land, 2, 2
Collisions type_player, type_obj, 2, 3
Collisions type_obj, type_obj, 2, 3




;Three changes here:

;slow down the jump acceleration to get a moon like jumping:
Const JumpAcceleration# = .5

;Gravitiy lokks realistic, when is is 10% of Jump acceleraion
Const Gravity# = .005

; has to be FLOAT not INT:
Player_velocityY# =0



Global player = CreateCube()
PositionEntity player, 0, 1, 0



Global OnGround


While Not KeyHit(1)
		;	OnGround = ( CollNY( player ) > 0 )
			
		;	If OnGround
				If KeyHit(57)
					; only one time. (if yoy simulate a rocket yu can add it more times)
					Player_velocityY = JumpAcceleration
				EndIf
		;	EndIf
			
			; always substract gravitiy, even when player is rising:
			Player_velocityY = Player_velocityY - Gravity
			
			
			TranslateEntity player, 0, Player_velocityy, 0
			
			;this is because you collision function is not working correct:
			If (EntityY(Player)<1.01) And Player_VelocityY<0 Then
				PositionEntity player, 0, 1, 0
				Player_VelocityY=0
			EndIf			
			
			
			PointEntity cam1, player
			
			
			
			UpdateWorld()
			RenderWorld()
			
			
			
			Text 0,20, "OnGround: "+OnGround
			Text 0,40, "EntityY#(player, true): "+EntityY#(player, True)
			Text 0,60, "Player_velocityy: "+Player_velocityy
			
			Flip 1

Wend
End


It seeems, that your ground detection is not proper working. I exchanged with a "If EntityY(Player)=0" test.

as a gift I added my "test-world". It is more realistic for testing cubes. It contains a sphere as sky, a green floor and a camera with fog. in combination it looks like a real outdoor scene.

Last edited 2012


Guy Fawkes(Posted 2012) [#6]
Thanks alot, Midimaster! :) It's PERFECT! :)



I DID make a SMALL addition though. To stop from multiple jumping, I made it so when ur in the air, u CANT keep pressing the Space key :)







Thanks again, Midimaster! :)