Does this help ?:
Graphics3D 1024,768,16,1
SetBuffer BackBuffer()
;The problem
;Run this program and hold down the cursor "right key"
;Then you see that the camera is acting like the player,
;because its a child, but that's not good because its moving,
;away from the object.
;in the tomb raider game the camera is not moving, and that's what
;i want , but its hard to make i think.
;i try to do a collions check when the camera is colli with a wall
;and then stops but that don't work for me.
;i hope you can make it
;don't need head turning or other diffec. things only the problem
;above. (only player is turning).
;THANKS VERY MUCH !!!!!
;GC-Martijn
Global level
Global player,p_body,p_head
Global p_x# = 0
Global p_y# = 1
Global p_z# = 14 ;now its at the wall
Global p_speed# = 1
Global p_pitch# = 0
Global p_yaw# = -90 ;now its like this |^ (|wall,^player)
Global p_roll# = 0
Global camera
Global c_x# = 0
Global c_y# = 6
Global c_z# = -14
Global c_speed# = 1
Global c_yaw# = 0
Global type_camera = 3
Global type_level = 2
Global type_player = 1
Const key_arrowpad_up = 200
Const key_arrowpad_left = 203
Const key_arrowpad_right= 205
Const Key_arrowpad_down = 208
; The Player
;---+
player = CreatePivot()
PositionEntity player,p_x#,p_y#,p_z#
RotateEntity player,p_pitch#,p_yaw#,p_roll#
EntityType player,type_player
;body
p_tex = LoadTexture("armour.pcx")
p_body = CreateCube(player)
ScaleMesh p_body,2,1,4
EntityTexture p_body,p_tex
;head
p_head = CreateCube(p_body)
ScaleMesh p_head,1.5,.6,2.2
EntityTexture p_head,p_tex
PositionEntity p_head,0,(p_y#+1),0
;De scene
; Ground
ground = CreatePlane()
ground_tex = LoadTexture("plane.jpg")
ScaleTexture ground_tex,20,17
EntityTexture ground,ground_tex
PositionEntity ground,0,0,0
EntityType ground,type_level
; Level
level = LoadMesh("level.3ds")
PositionEntity level,30,-1,0
EntityType level,type_level
ScaleEntity level,2,2,2
; Create Camera
camera = CreateCamera() ;p_body)
PositionEntity camera,c_x#,c_y#,c_z#
EntityType camera,type_camera
; Handle Collisions
Collisions type_player,type_level,2,2
Collisions type_camera,type_level,2,2
; Light
AmbientLight 255,255,255
;Game Loop
;------------------------------------------------
While Not KeyHit(1)
reset_vars()
player_move()
camera_move(camera,player,c_x,c_y,c_z)
UpdateWorld
RenderWorld
player_info()
Flip
Wend
End
;------------------------------------------------
Function player_move()
If KeyDown(key_arrowpad_left) Then
TurnEntity player,0,1,0
EndIf
If KeyDown(key_arrowpad_right) Then
TurnEntity player,0,-1,0
EndIf
If KeyDown(key_arrowpad_up) Then
p_z#=+p_speed#
MoveEntity player,p_x#,p_y#,p_z#
EndIf
If KeyDown(key_arrowpad_down) Then
p_z#=-p_speed#
MoveEntity player,p_x#,p_y#,p_z#
EndIf
End Function
Function player_info()
Text 0,FontHeight()*1,"p_x:"+EntityX(player)
Text 0,FontHeight()*2,"p_y:"+EntityY(player)
Text 0,FontHeight()*3,"p_z:"+EntityZ(player)
Text 0,FontHeight()*4,"p_speed:"+p_speed#
Text 0,FontHeight()*5,"p_yaw:"+EntityYaw(player)
Text 0,FontHeight()*6,"p_roll:"+EntityRoll(player)
Text 0,FontHeight()*7,"p_pitch:"+EntityPitch(player)
Text 0,FontHeight()*8,"p_collisions:"+CountCollisions(player)
Text 0,FontHeight()*9,"level distance:"+ProjectedX#()
End Function
Function reset_vars()
p_x# = 0
p_y# = 0
p_z# = 0
p_pitch# = 0
p_yaw# = 0
p_roll# = 0
End Function
Function camera_move(camera,entity,camx#,camy#,camz#,aimx#=0,aimy#=0,aimz#=0,smoothcam#=0.2,roll#=0)
TFormPoint camx#,camy#,camz#,entity,0
dx#=(TFormedX()-EntityX(camera))*smoothcam#
dy#=(TFormedY()-EntityY(camera))*smoothcam#
dz#=(TFormedZ()-EntityZ(camera))*smoothcam#
TranslateEntity camera,dx,dy,dz
TFormPoint aimx#,aimy#,aimz#,entity,0
dx# = EntityX(camera)-TFormedX()
dy# = EntityY(camera)-TFormedY()
dz# = EntityZ(camera)-TFormedZ()
dist#=Sqr#((dx#*dx#)+(dz#*dz#))
pitch#=ATan2(dy#,dist#)
yaw#=ATan2(dx#,-dz#)
RotateEntity camera,pitch#,yaw#,roll#
End Function
|