Well i think I know what your doing:
at the end of the code you are aligning your pivot to the terrain, so do this:
at the begging of your loop I reset the valus of:
align=0
;changed jumpkey to this
If keyhit(57)=true align=2
then at the end
positionentity camera_pivot,x#,terr_y#+align,z#
Here I'll adjust your code:
;graphics
Graphics3D 800,600
SetBuffer BackBuffer()
;GLOBALS+added align
Global x#,y#,z#,terra_y#,align
;collision groups
Global SCENERY = 1
Global PLAYER = 2
;light
Global light = CreateLight()
RotateEntity light, 90,0,0
;CAMERA PIVOT
camera_pivot= CreatePivot()
EntityRadius camera_pivot,1.4
EntityType camera_pivot,PLAYER
;CAMERA
Global camera = CreateCamera(camera_pivot)
CameraRange camera,1,1000
CameraFogMode camera,1
CameraFogRange camera,160,200
;SKY
Global sky = CreateSphere(16,camera_pivot)
FlipMesh sky
ScaleEntity sky,100,100,100
PositionEntity sky, 0,50,0
sky_tex = LoadTexture("sky.bmp")
EntityTexture sky,sky_tex
;TERRAIN
Global terrain = LoadTerrain("height2.jpg")
TerrainDetail terrain,2500,True
ScaleEntity terrain, 3,100,3
PositionEntity terrain,-1000,0,-530
ter_tex = LoadTexture("mossyground.bmp")
EntityTexture terrain,ter_tex
EntityRadius terrain,0.2
EntityType terrain,SCENERY
;main loop
While Not KeyHit(1)
align=0 ;added align set to 0 every loop
; use the mouse to look around
TurnEntity camera_pivot, 0, 0 -MouseXSpeed(), 0
TurnEntity camera_pivot, MouseYSpeed(), 0, 0
RotateEntity camera_pivot, EntityPitch#(camera_pivot),EntityYaw#(camera_pivot),0
RotateEntity camera_pivot,EntityPitch#(camera_pivot),EntityYaw#(camera_pivot),0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
; use the w,a,s,d or arrow keys for walking and strafing
If KeyDown(17) Or KeyDown(200) MoveEntity camera_pivot,0,0,0.10
If KeyDown(31) Or KeyDown(208) MoveEntity camera_pivot,0,0,-0.10
If KeyDown(30) Or KeyDown(203) MoveEntity camera_pivot,-0.10,0,0
If KeyDown(32) Or KeyDown(205) MoveEntity camera_pivot,0.10,0,0
If KeyHit(57) align=2
x#=EntityX(camera_pivot)
y#=EntityY(camera_pivot)
z#=EntityZ(camera_pivot)
UpdateWorld
terra_y#=TerrainY(terrain,x#,y#,z#)+2.0
PositionEntity camera_pivot,x#,terra_y#+align,z#
RenderWorld
Flip
Wend
End
furthermore I would use:
If keyhit(57)=true or keydown(57)=true align=2
I seem to have trouble reading a keyhit each time, sometimes it reads as key down, and i've even tried enabling directinput. Maybe theres a better way then resetting the value each loop, but i'm not sure.