third-person camera?

Blitz3D Forums/Blitz3D Beginners Area/third-person camera?

Cubed Inc.(Posted 2010) [#1]
Does anyone know how to make a third-person camera? I'm trying to make a Lego game similair to Lego Island 2 becuase I think that it might be good to make a simple platform game before I make a more complex one. If someone can help, it would be greatly apprectiated.
please reply.later.

P.S Lego is in copyright of the Lego company, not me.


GIB3D(Posted 2010) [#2]
I made this myself and is one of the many things I made and stored away in a nice folder so I can pull it out later if I need it.




Kryzon(Posted 2010) [#3]
I'd say the most important thing for you is to play a game and study how THEY did it ('they' being professional game designers + programmers).
Blitz3D implementation will definitely not be hard, once you recognize all the features the camera-systems you like have (of course, implementation will only be easy if you know the Blitz3D command set!).

You can learn a lot from analyzing games (especial some moderately old ones, like N64 games). If you're accepting suggestions, try playing Banjo-Kazooie\Tooie or Castlevania 64.

They have different 3rd-person camera implementations (in my opinion, the Banjo camera is the best one; not only it follows the player in open environments, but it also has "rails" for when in tight corners or tunnels - something most people around here forget to use).
Don't make it just a "stand behind the character" camera.


GIB3D(Posted 2010) [#4]
The one I posted is a Grand Theft Auto camera style.


Cubed Inc.(Posted 2010) [#5]
GIB3D
The code you gave me was great, but it was kinda complex and it fitted more for a shooting game, rather than a platforming/action adventure game. I have studied and watched videos of Lego Island 2 and I noticed, even how simple the camera was, it worked. You couldn't rotate the camera, but the characters movement did all of the rotating for it(for example, when the character walks right and left or at an angle, the camera rotates)if you see any videos of the game on youtube, you'll know what I mean. The code was great, but I just want to use a simple camera before I get into more complex 3rd person game mechanics(such as in gta). Thanks anyway.


GIB3D(Posted 2010) [#6]
Basically what I did for the camera was parent a Camera to a Pitch Pivot then parent that to a Yaw Pivot. How the Yaw pivot turns is your choice.


Ross C(Posted 2010) [#7]
I have some code for this. The camera has a little bit of intelligence about it . Fairly simple. I will try and get it when PC is up and running again.


Zethrax(Posted 2010) [#8]
The Castle demo in the 3d samples for Blitz3D has a good third person camera ( C:\Program Files\Blitz3D\samples\mak\castle ).

Regarding the 'Lego' bit - make sure that you don't violate any trademarks or other intellectual property rights with your game, or you could find yourself in serious legal trouble.


Cubed Inc.(Posted 2010) [#9]
Bill Stanbrook
Don't worry, i'm not releasing the game or anything. Just for practice:)

GIB3D
Before I made this post, I tried to parent the camera with a pivot that would be contolled by the character, but it was acting weird and broken.

Ross C
Please explain the camera code when you get the chance.


Ross C(Posted 2010) [#10]
What i do, is a slightly modifed version of the pivot style camera, parented to the entity. I firstly create a pivot, and parent it to the entity you want to follow. Then, i position it, where it would want my camera to rest behind the entity, when no movement is happening.

Then, each loop, i do the following:

PointEntity camera,pivot
MoveEntity camera,0,0,EntityDistance(camera,pivot)/10 ; A higher dividing number will cause a slower and smoother camera
PointEntity camera,entity


camera being your camera
pivot being the pivot i described earlier
entity being the entity you want the camera to follow.

I have slightly modified it, for greater control, and so it doesn't get stuck, but try that and see if it does what you need.


Cubed Inc.(Posted 2010) [#11]
Ross C
The trouble that i'm having is that I can't make the camera follow the pivot and I can't make the pivot stick to the player. When I tried your code, the camera didn't follow the player, it just pointed and zoomed.


Naughty Alien(Posted 2010) [#12]
..here is one more basic cookie from my 'kitchen'..i hope it helps... :)

Graphics3D 1280,1024,32,1
SetBuffer=BackBuffer()
Global FreeLookXS#, FreeLookZS#, FreeLookRotXS#, FreeLookRotYS#,Pitch#

Global campivot=CreateCube() ; create pivot for camera
Global camera=CreateCamera()  ; create camera (!!!)

; ---------------------- LETS GENERATE SOME JUNK AROUND THE WORLD ---------------

Global light=CreateLight()
Global player=CreateCube()    ; create simple player
Global Player_Free_Look=CreatePivot(player)
MoveEntity Player_Free_Look,0,4,0
Global plane=CreatePlane()   ; create simple floor
MoveEntity player,0,1,0
; Create texture of size 256x256
tex=CreateTexture(256,256)

; Set buffer - texture buffer
SetBuffer TextureBuffer(tex)

; Clear texture buffer with background white color
For i=1 To 10
Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
Rect Rnd(0,256),Rnd(0,256),Rnd(0,256),Rnd(0,256)
Next

; Texture cube with texture
EntityTexture plane,tex
EntityTexture player,tex

; Set buffer - backbuffer
SetBuffer BackBuffer()

;camera look variables
; ------------------------------------------------------------------------------------------------

While Not KeyHit(1)
;object movement according to mouse pointer position

	FreeLook(player,Player_Free_Look, .1)
	CamFollow(camera,Player_Free_Look,.18,8,0,0,0)
	

RenderWorld

VWait:Flip False

Wend

End



Function CamFollow(cam,ent,cspeed#,dist#,hite#,xrot#,tilt#)

TFormPoint 0,hite#,-dist#,ent,0

cx#=(TFormedX()-EntityX(cam))*cspeed#
cy#=(TFormedY()-EntityY(cam))*cspeed#
cz#=(TFormedZ()-EntityZ(cam))*cspeed#

TranslateEntity cam,cx,cy,cz

RotateEntity cam,xrot#,EntityYaw(cam),tilt#
PointEntity cam,ent
End Function

Function FreeLook(Object_Horizontal,Object_Vertical, sp# = .1)
If sp# > 0 Then
    Side_Direction=((KeyDown(32) Or KeyDown(205)) - (KeyDown(30) Or KeyDown(203)))
    Front_Direction=((KeyDown(17) Or KeyDown(200)) - (KeyDown(31) Or KeyDown(208)))
	FreeLookXS# = (FreeLookXS# + Side_Direction * (sp#/2)) * .75
	FreeLookZS# = (FreeLookZS# + Front_Direction * sp#) * .75
	MoveEntity Object_Horizontal, FreeLookXS#, 0, FreeLookZS#
EndIf

FreeLookRotXS# = ((MouseXSpeed() - FreeLookRotXS#) * .2 + FreeLookRotXS#) * .45
FreeLookRotYS# = ((MouseYSpeed() - FreeLookRotYS#) * .2 + FreeLookRotYS#) * .45
If EntityPitch(Object_Vertical) + FreeLookRotYS# < -25 Pitch# = -25 ElseIf EntityPitch(Object_Vertical) + FreeLookRotYS# > 45 Pitch# = 45 Else Pitch# = EntityPitch(Object_Vertical) + FreeLookRotYS#
yaw# = -FreeLookRotXS# + EntityYaw(Object_Horizontal)
RotateEntity Object_Horizontal, 0, yaw#, 0
RotateEntity Object_Vertical, Pitch#, 0, 0
MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
End Function



Cubed Inc.(Posted 2010) [#13]
Your example codes are really good and usefull, but I think that I would understand them more if I knew what makes the camera follow the main player in it. Can someone give me a explaination?


Kryzon(Posted 2010) [#14]
All the camera positioning code is in the CamFollow() function.

TFormPoint 0,hite#,-dist#,ent,0
This command calculates the XYZ coordinates of the 3D point you specify.

It's like a 'relative' point, because you specify from which entity you will be moving away from, and also specify the X, Y and Z vectors you are going to be moving away with.

Translating the TFormPoint usage above would be: I want to move away from entity "ent" (TFormPoint 0,hite#,-dist#,ent,0), by such value in the X axis (TFormPoint 0,hite#,-dist#,ent,0), by the value "hite#" in the Y axis (TFormPoint 0,hite#,-dist#,ent,0) and by value "-dist#" on the Z axis (TFormPoint 0,hite#,-dist#,ent,0). Note that the last parameter is 0, and that tells TFormPoint to convert the point's coordinates into global coordinates. This way the point will always be behind the player wherever he is, instead of close to the origin of the 3D world.

The way it's being used in that code, it calculates the coordinates of a point in 3D space that's just a bit back from the target entity (the effect of the -dist# in the Z axis). Try playing with "hite#" and "-dist#" values. If you put a positive value in hite#, like 5, for instance, the camera would be a bit higher.

He then slowly moves the camera into this point in space by using this code:
cx#=(TFormedX()-EntityX(cam))*cspeed#
cy#=(TFormedY()-EntityY(cam))*cspeed#
cz#=(TFormedZ()-EntityZ(cam))*cspeed#

Multiplying 'how much the camera has to move to be in that 3D point' by Cspeed#, which is a small floating point value, gives the movement a slow and non-linear nature. The camera moves faster when far from the 3D point's current position, but slower the closer it gets.

He then moves the camera independently from it's current orientation:
TranslateEntity cam,cx,cy,cz

(Those cx, cy and cz values will eventually be equal to the 3d point calculated by TFormPoint, if the player stays still long enough)

Then you keep the camera pointing the target entity (in that case, the player) with PointEntity, so as to keep the player centered on the screen.


Cubed Inc.(Posted 2010) [#15]
Thanks for the explaination:)I studied the castle demo and put it's code into my game test. When I did, the camera was put a weird angles. Can someone help me out?
Here's my code(sorry if it's long)
;Lego Island Rescue;
Graphics3D 1366,768,32,1
SetBuffer BackBuffer ()

Const GRAVITY#=-1

Const TYPE_PLAYER=1,TYPE_TARGET=3,TYPE_WATER=3
Const TYPE_SCENERY=10,TYPE_TERRAIN=11

Collisions TYPE_PLAYER,TYPE_TERRAIN,2,3
Collisions TYPE_PLAYER,TYPE_SCENERY,2,2
Collisions TYPE_TARGET,TYPE_TERRAIN,2,2
Collisions TYPE_TARGET,TYPE_SCENERY,2,2

;Lego Island;
island=LoadMesh("media/tower.b3d")
islandtex=LoadTexture("media/Untitled2.png",256)
PositionEntity island,0,-150,60
ScaleEntity island,4,4,4
EntityFX island,0
EntityType island,TYPE_TERRAIN

;Lego Island;
island2=LoadMesh("media/tower.b3d")
islandtex2=LoadTexture("media/Untitled2.png",256)
PositionEntity island2,0,-150,5360
ScaleEntity island2,4,4,4
EntityFX island2,0
EntityType island2,TYPE_TERRAIN

;player;
player=CreateCube()
PositionEntity player,0,100,0
ScaleEntity player,4,4,4
EntityType player,TYPE_PLAYER

;water;
water = CreatePlane ()
h20 = LoadTexture ("media/water_tex.jpg",256)
ScaleTexture h20, 200, 200
EntityTexture water, h20
EntityAlpha water, 0.4
PositionEntity water,0,-140,60
EntityFX water,1
EntityType water,TYPE_TERRAIN

;light;
light=CreateLight()

;camera (AKA the player);
camera=CreateCamera()
EntityRadius camera,30
PositionEntity camera,0,100,-50
EntityType camera,TYPE_PLAYER

;target;
target=CreatePivot( player )

;sky/fog/range;
CameraFogMode camera,1
CameraFogColor camera,200, 220, 255
CameraRange camera, 1,5500
CameraFogRange camera,1,2500-10
CameraClsColor camera,200,220,255

;move camera;
While Not KeyDown(1)
dx#=EntityX( target,True )-EntityX( camera )
dy#=EntityY( target,True )-EntityY( camera )
dz#=EntityZ( target,True )-EntityZ( camera )
TranslateEntity camera,dx*.1,dy*.1,dz*.1
PointEntity camera,player
TranslateEntity player,0,GRAVITY,0
If KeyDown(200)
MoveEntity player,0,0,3
EndIf
If KeyDown(208)
MoveEntity player,0,0,-3
EndIf
If KeyDown(203)
TurnEntity player,0,3,0
EndIf
If KeyDown(205)
TurnEntity player,0,-3,0
EndIf

UpdateWorld
RenderWorld
Flip
Wend
End


Kryzon(Posted 2010) [#16]
You created a pivot but didn't distance it from the player properly. Move the "target" with something like this, as soon as you create it:

MoveEntity Target,0,2,-7


Cubed Inc.(Posted 2010) [#17]
Kryzon
Thanks. My camera is still kinda glitchy and it sometimes gets stuck, but it's a good start. Thanks to everyone btw:)