Chase Cam

Blitz3D Forums/Blitz3D Beginners Area/Chase Cam

Happy Llama(Posted 2011) [#1]
Hi i am making a simple came where the camera follows the player. I have added a simple chase cam that follows the player but does not rotate with it. Please help!



Graphics3D 1000,700,64,3

Const gravity=0.3

sun=CreateLight()

playercam=CreateCamera()
RotateEntity playercam,30,0,0


ground=CreatePlane()
PositionEntity ground,0,-10,0
groundtex=LoadTexture("terrain-1.jpg")
EntityTexture ground, groundtex
ScaleTexture groundtex,50,50

player=CreateCube()
EntityColor player,0,255,0



While Not KeyDown (1)

If KeyDown(200) MoveEntity player,0,0,1
If KeyDown(208) MoveEntity player,0,0,-1
If KeyDown(203) TurnEntity player,0,3,0
If KeyDown(205) TurnEntity player,0,-3,0

PositionEntity playercam,EntityX(player),EntityY(player),EntityZ(player)
MoveEntity playercam,0,0,-5


UpdateWorld
RenderWorld

Flip


Wend

End

Thanks!

Last edited 2011


Rob the Great(Posted 2011) [#2]
There are many ways to control a camera, but for what it sounds like you're trying to do, give one of these two examples a try. The first one positions the camera where you want it to be relative to the player, and then sets EntityParent camera,player so that it follows the player's movements:
Graphics3D 640,480,0,2

SetBuffer BackBuffer()

Global player = CreateCube()

Global camera = CreateCamera()
MoveEntity camera,0,0,-5
EntityParent camera,player

Global ground = CreatePlane()
EntityColor ground,0,255,0
MoveEntity ground,0,-1,0

While Not KeyDown(1)

   If KeyDown(200) Then MoveEntity player,0,0,1
   If KeyDown(208) Then MoveEntity player,0,0,-1
   If KeyDown(203) Then TurnEntity player,0,3,0
   If KeyDown(205) Then TurnEntity player,0,-3,0

   RenderWorld
   Flip

Wend

End

The other option is a little more complex. Basically, you create a camera pivot, make the camera pivot the parent entity of the camera, position the camera pivot where the player is at every logic loop, point the camera at the player every loop, rotate the camera pivot (orbiting the camera) if they push the A or D keys, and then move the camera closer or further to the camera pivot if they push the W or S keys and reparent to the pivot. This sounds complex, but it's not too bad. Just call UpdateCamera() every loop and you're set. Keep in mind that this is untested and is only meant for concept purposes. If you do wish to use this, make sure you add in actual scancodes in place of the KeyDown() letters in the UpdateCamera() function.
Graphics3D 640,480,0,2

SetBuffer BackBuffer()

Global player = CreateCube()

Global camera = CreateCamera()
MoveEntity camera,0,0,-5
Global camerapivot = CreatePivot()
EntityParent camera,camerapivot

Global ground = CreatePlane()
EntityColor ground,0,255,0
MoveEntity ground,0,-1,0

While Not KeyDown(1)

   If KeyDown(200) Then MoveEntity player,0,0,1
   If KeyDown(208) Then MoveEntity player,0,0,-1
   If KeyDown(203) Then TurnEntity player,0,3,0
   If KeyDown(205) Then TurnEntity player,0,-3,0

   UpdateCamera()

   RenderWorld
   Flip

Wend

Function UpdateCamera()

   PointEntity camera,player

   PositionEntity camerapivot,EntityX(player),EntityY(player),EntityZ(player)

   If KeyDown(A)
      TurnEntity camerapivot,0,1,0
   EndIf

   If KeyDown(D)
      TurnEntity camerapivot,0,-1,0
   EndIf

   If KeyDown(W)
      If EntityDistance(player,camera) > 3
         EntityParent camera,0
         PointEntity camera,player
         MoveEntity camera,0,0,1
         EntityParent camera,camerapivot
      EndIf
   EndIf

   If KeyDown(S)
      If EntityDistance(player,camera) < 10
         EntityParent camera,0
         PointEntity camera,player
         MoveEntity camera,0,0,-1
         EntityParent camera,camerapivot
      EndIf
   EndIf

End Function

End



Happy Llama(Posted 2011) [#3]
The camera still wont rotate with the cube. Any ideas on how to do that?


Rob the Great(Posted 2011) [#4]
I don't think I follow...That first example should do that. I might have done something wrong, it was all written on the fly.

What do you mean by "rotate with the cube"? Something more like the camera movement in the castle demo?


Krischan(Posted 2011) [#5]
Hmm, do you want this effect (based on your code)?



My own Third/Chasecam code goes like that:






Happy Llama(Posted 2011) [#6]
Thanks I was trying to get an effect on where the camera always looks at the back of the character. Thanks Krischan, that is exactly what is was looking for.

Last edited 2011