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
|