Hi all. I have been studying up on gravity and stuff like that, so i decided to use this code i found on the forums.
Now I modified it a little bit to what i wanted, but there are 2 problems on it.
The 1st problem is why everytime do i move, my screen flickers this weird line created from the sky sphere i made.
and the 2nd thing. why every once in a while does my player not move when he moves or jumps or lands?
image:
![](http://i406.photobucket.com/albums/pp148/DarkShadowWing/zorder.png)
code:
Graphics3D 800,600, 32, 2
AntiAlias 1
WBuffer 1
SetBuffer BackBuffer()
;Collision Setup
Global MaxCol = MaxCollisions(3)
Dim Col(MaxCol)
CollisionSetup()
Global camera = CreateCamera()
CameraRange camera, .1, 9999
Global sky = CreateSphere(100.5)
EntityOrder sky, 10
ScaleEntity sky, 100, 100, 100
EntityColor sky, 68, 207, 252
FlipMesh sky
PositionEntity camera,0,5,-5
RotateEntity camera, 30, 0, 0
Global light = CreateLight()
Global cube = CreateCube()
EntityRadius cube, 1, 2
EntityType(cube, Col(1))
Global jump_value = 0
Global jump_flag = 0
;Lighting
SceneLight = CreateLight()
groundtexture=CreateTexture(32,32,1+8)
SetBuffer TextureBuffer(groundtexture)
Color 80,80,80
Rect 0,0,32,32,1
Color 100,100,100
Rect 0,0,32,32,0
ScaleTexture groundtexture,2,2
SetBuffer BackBuffer()
Color 255,255,255
pl=CreatePlane()
PositionEntity pl,0,-1,0
EntityOrder pl, 1
EntityTexture pl,groundtexture
EntityPickMode pl,2
EntityType pl,Col(2)
EntityColor pl,255,255,255
While Not KeyHit(1)
PositionEntity sky, EntityX(cube), EntityY(cube), EntityZ(cube)
PositionEntity camera, EntityX(cube), EntityY(cube)+5, EntityZ(cube)-5
If Not KeyDown(42)
If KeyDown(200) Or KeyDown(208) Or KeyDown(17) Or KeyDown(31)
speed# = .1
jspeed# = 10
EndIf
Else If KeyDown(42)
If KeyDown(200) Or KeyDown(208) Or KeyDown(17) Or KeyDown(31)
speed# = .2
jspeed# = 10
EndIf
EndIf
tspeed# = speed#
acceleration# = Cos(jump_value)/jspeed#
TurnEntity cube, 0, (KeyDown(203)-KeyDown(205)) Or (KeyDown(30)-KeyDown(32))*tspeed#, 0
MoveEntity cube, 0, 0, (KeyDown(200)-KeyDown(208))*speed#
gravity# = gravity# - .01
If gravity# < -1 Then gravity# = -1
If KeyHit(57) And jump_flag = 0 Then
jump_flag = 1
End If
If jump_flag = 0 Then
y# = EntityY(cube)
gy# = EntityY(pl)
If y# <= gy# Then y# = gy# : gravity# = 0
MoveEntity cube, 0, y#+gravity#, 0
Else If jump_flag = 1 Then
MoveEntity cube,0,acceleration#,0
jump_value = jump_value + 2
If jump_value >60 Then
jump_flag = 2
End If
ElseIf jump_flag = 2 Then
MoveEntity cube,0,-Cos(jump_value)/jspeed#,0
jump_value = jump_value - 2
If jump_value < 0 Then
jump_flag = 0
jump_value = 0
End If
End If
UpdateWorld
RenderWorld
Text 10, 10, gravity#
Text 10, 30, "Jump: "+EntityY(cube)
Flip
Wend
Function MaxCollisions(number%)
Return number
End Function
Function CollisionSetup()
For mc = 2 To MaxCol
Col(mc) = mc
Col(1) = 1
Collisions Col(1),Col(mc),2,2
Next
End Function
ANY help is GREATLY appreciated! :)
~DS~
|