Here is my code, I hope somebody modify for better
;*************
;by Mike0101
;I'm sure somebody makes better this weak code
;but this code works right
;*************
;System
Global screen_width% = 1024
Global screen_height% = 768
Global screen_halfwidth% = screen_width/2
Global screen_halfheight% = screen_height/2
Global camHeight#=4 ; default height of the camera behind the player
Global camDist#=-7 ; default distance of the camera behind the player
Global dest_xang#
Global dest_yang#
;CONST
Const C_PLAYER=1, C_LEVEL=2
AppTitle "TPS Camera"
HidePointer
;Screen
Graphics3D screen_width,screen_height,32,2
SetBuffer BackBuffer()
;Light
light=CreateLight()
;Plan
plan=CreatePlane()
EntityColor plan,255,0,0
EntityType plan, C_LEVEL
;OBJECT
cube1=CreateCube()
ScaleEntity cube1,10,10,10
PositionEntity cube1,13,0,13
EntityType cube1,C_LEVEL
;CAMERA
camera =CreateCamera()
;Player Pivot
plpivot=CreatePivot()
EntityType plpivot, C_PLAYER
EntityRadius plpivot,1.8,3
PositionEntity plpivot, 0, 1,0
;Player, now a cube but you can change for a nice model
Player=CreateCube(plpivot)
ScaleEntity player,1,3,1
EntityColor Player,255,0,255
;I'm using 2 pivots for camera controlling
;Pivot for the camera controlling
;One Front of the player,
FrontPivot=CreatePivot(plpivot)
PositionEntity Frontpivot,0,4,10
;One behind the player
;This pivot controlls the collisions and "finds" the right position of the camera behind player
Backpivot=CreatePivot(plpivot)
EntityRadius Backpivot,1
EntityType BackPivot, C_PLAYER
Collisions C_PLAYER, C_LEVEL ,2,2
While Not KeyHit(1)
UpdateCamera(plpivot,MouseXSpeed(),MouseYSpeed(), Frontpivot, Backpivot, Camera)
UpdateWorld
RenderWorld
; Crosshair :)
Text screen_halfwidth%, screen_halfheight%, "+"
Flip
Wend
End
Function updatecamera(ent,mxs#, mys#, pivot1, pivothatso, camera)
;ent : Player pivot
;mxs: MouseXmove
;mys: MouseYmove
;pivot1: pivot before player
;pivothatso: pivot front player
;Camera: ....What do you think:)
MoveMouse screen_halfwidth%, screen_halfheight%
; Limit of the "look up", "look down"
If dest_xang + mys > 120 Or dest_xang + mys < -45 Then ;
mys=0
EndIf
dest_xang# = dest_xang + mys
; When the player looks up, the front pivot moves UP, when looks down the back pivot moves down
TranslateEntity pivot1,0,-MYS#*.15,0
angle#= Sin(EntityPitch(camera))*10
tempkkammag#=(camheight + angle)
tempkkamtav#= camdist - Abs( angle)
dest_yang# = dest_yang - (mxs*.5)
RotateEntity ent, 0, dest_yang,0
;Velocity of camera movement and position according of collision
dx#=(EntityX(pivothatso,True)-EntityX(camera,True)) * .1
dy#=(EntityY(pivothatso,True)-EntityY(camera,True)) *.9
dz#=(EntityZ(pivothatso,True)-EntityZ(camera,True)) *.1
TranslateEntity camera,dx,dy,dz
PointEntity camera,pivot1
PositionEntity pivothatso,0,0,0
ResetEntity pivothatso
PositionEntity pivothatso,0,tempkkammag,tempkkamtav
End Function
;*************
;by Mike0101
;I'm sure somebody makes better this weak code
;but this code works right
;*************
;System
Global screen_width% = 1024
Global screen_height% = 768
Global screen_halfwidth% = screen_width/2
Global screen_halfheight% = screen_height/2
Global camHeight#=4 ; default height of the camera behind the player
Global camDist#=-7 ; default distance of the camera behind the player
Global dest_xang#
Global dest_yang#
;CONST
Const C_PLAYER=1, C_LEVEL=2
AppTitle "TPS Camera"
HidePointer
;Screen
Graphics3D screen_width,screen_height,32,2
SetBuffer BackBuffer()
;Light
light=CreateLight()
;Plan
plan=CreatePlane()
EntityColor plan,255,0,0
EntityType plan, C_LEVEL
;OBJECT
cube1=CreateCube()
ScaleEntity cube1,10,10,10
PositionEntity cube1,13,0,13
EntityType cube1,C_LEVEL
;CAMERA
camera =CreateCamera()
;Player Pivot
plpivot=CreatePivot()
EntityType plpivot, C_PLAYER
EntityRadius plpivot,1.8,3
PositionEntity plpivot, 0, 1,0
;Player, now a cube but you can change for a nice model
Player=CreateCube(plpivot)
ScaleEntity player,1,3,1
EntityColor Player,255,0,255
;I'm using 2 pivots for camera controlling
;Pivot for the camera controlling
;One Front of the player,
FrontPivot=CreatePivot(plpivot)
PositionEntity Frontpivot,0,4,10
;One behind the player
;This pivot controlls the collisions and "finds" the right position of the camera behind player
Backpivot=CreatePivot(plpivot)
EntityRadius Backpivot,1
EntityType BackPivot, C_PLAYER
Collisions C_PLAYER, C_LEVEL ,2,2
While Not KeyHit(1)
UpdateCamera(plpivot,MouseXSpeed(),MouseYSpeed(), Frontpivot, Backpivot, Camera)
UpdateWorld
RenderWorld
; Crosshair :)
Text screen_halfwidth%, screen_halfheight%, "+"
Flip
Wend
End
Function updatecamera(ent,mxs#, mys#, pivot1, pivothatso, camera)
;ent : Player pivot
;mxs: MouseXmove
;mys: MouseYmove
;pivot1: pivot before player
;pivothatso: pivot front player
;Camera: ....What do you think:)
MoveMouse screen_halfwidth%, screen_halfheight%
; Limit of the "look up", "look down"
If dest_xang + mys > 120 Or dest_xang + mys < -45 Then ;
mys=0
EndIf
dest_xang# = dest_xang + mys
; When the player looks up, the front pivot moves UP, when looks down the back pivot moves down
TranslateEntity pivot1,0,-MYS#*.15,0
angle#= Sin(EntityPitch(camera))*10
tempkkammag#=(camheight + angle)
tempkkamtav#= camdist - Abs( angle)
dest_yang# = dest_yang - (mxs*.5)
RotateEntity ent, 0, dest_yang,0
;Velocity of camera movement and position according of collision
dx#=(EntityX(pivothatso,True)-EntityX(camera,True)) * .1
dy#=(EntityY(pivothatso,True)-EntityY(camera,True)) *.9
dz#=(EntityZ(pivothatso,True)-EntityZ(camera,True)) *.1
TranslateEntity camera,dx,dy,dz
PointEntity camera,pivot1
PositionEntity pivothatso,0,0,0
ResetEntity pivothatso
PositionEntity pivothatso,0,tempkkammag,tempkkamtav
End Function