This should do the trick. You MUST give your terrain mesh a pickmode. Make sure it's set to polygon detection :o)
;linepick example by RossC
Graphics3D 800,600
SetBuffer BackBuffer()
Global camera = CreateCamera()
Global light = CreateLight()
Global player = CreateCone()
EntityType player,1
EntityRadius player,1
EntityColor player,50,70,255
PositionEntity player,0,0.5,0
Global cam_piv = CreatePivot(player)
PositionEntity cam_piv,0,2,-8
Global tex=CreateTexture(64,64,1+8)
SetBuffer TextureBuffer(tex)
For loop=0 To 3000
Color Rnd(190,255),Rnd(190,255),Rnd(190,255)
Rect Int(Rnd(0,63)),Int(Rnd(0,63)),1,1
Next
Color 255,255,255
SetBuffer BackBuffer()
Global plane=CreatePlane()
EntityType plane,2
EntityColor plane,200,100,120
EntityTexture plane,tex
EntityPickMode plane,2
Global sphere=CreateSphere(10)
ScaleEntity sphere,10,3,10
EntityPickMode sphere,2
EntityType sphere,2
PositionEntity sphere,-2,0,19
Collisions 1,2,2,2; set up collisions between the ground and the player
Global jump_force#
Global jump_flag=0; set jump flag to 'no jump'
Global gravity#=0.9; set gravity value
While Not KeyHit(1)
; this part is the linepick. The tform part, is to make sure the linepick is done from the players
; actual rotation, straigh down.
TFormVector 0,-10,0,player,0
; the values from the tform then get used in the linepick command. if you just substitute your
; variable for the player into here, everything will be cool!
LinePick(EntityX(player,True),EntityY(player,True),EntityZ(player,True),TFormedX(),TFormedY(),TFormedZ()); do a linepick straight down form the players location
; aligns the player to the scenery, whatever has has a pickmode set.
AlignToVector player,PickedNX(),PickedNY(),PickedNZ(),2,0.1
If KeyDown(200) Then MoveEntity player,0,0,0.1
If KeyDown(208) Then MoveEntity player,0,0,-0.1
If KeyDown(203) Then TurnEntity player,0,1,0
If KeyDown(205) Then TurnEntity player,0,-1,0
update_camera()
UpdateWorld
RenderWorld
Text 0,0," Press Space to jump. Arrow keys to move!"
;DebugLog(" pickedy="+PickedY())
Flip
Wend
End
Function update_camera()
PointEntity camera,cam_piv
MoveEntity camera,0,0,EntityDistance#(camera,cam_piv)/40.0
PointEntity camera,player
End Function
|