Third person cameras..

Blitz3D Forums/Blitz3D Programming/Third person cameras..

xmlspy(Posted 2005) [#1]
What's the best third person camera example made in B3D? I have noticed that creating a proper camera system is quite hard, is there any good examples out there? Especially for a closed dungeon like environment.


Filax(Posted 2005) [#2]
Castle blitz sample ?


Ross C(Posted 2005) [#3]
You will need to give the camera a collision mode so, it doesn't go through walls. Also, you will need to keep an eye on the distance between the player and camera, to make sure the camera doesn't get snagged on anything. I find it best not to parent the camera to the player, but to constantly point the camera at a pivot, parented to the player. You place the pivot where you want the camera to rest. Then, point the camera at the player, and then, each loop...


PointEntity camera, player_pivot
MoveEntity camera,0,0, EntityDistance#(camera,player_pivot)/30.0 ; 30 is just an example number. Higher numbers will result in slowly following speed.
PointEntity camera,player



Do that every loop, and you should have a smooth camera.


xmlspy(Posted 2005) [#4]
Thx Ross, I'll be using a similar method in conjunction with http://www.blitzbasic.com/codearcs/codearcs.php?code=1528 to make the system the way I want it. No more worries about the camera collisions.


jfk EO-11110(Posted 2005) [#5]
COllision on cameras may produce a lot of problems, like a camera that is struck inside a corner etc. IMHO the best method is: Use a number of linepicks from the wanted camera-position to the closest possible camera position (cose to the player character) until the linepick returns the characters handle, so you'll know it's visible. When there is a wall between the wanted camera position and the character, the camera will automaticly go as close as neccessary to the character. To find this point I'd suggest to do a binary search:
let's say the full distance is 100%
visible at full distance ? no!
visible at 50% dist? no!
visible at 25% dist? yes!
visible at (25%+12.5%= 37.5%) dist? no!
visible at (25%+6.25%) dist? yes!
visible at (25%+6.25%+3.125%) no!
visible at (25%+6.25%+1.5625%) yes!
and so on, it's up to you to define the max resolution for this search, but you see even here we got 1.5% resolution with only 7 linepicks.


Naughty Alien(Posted 2005) [#6]
I dont know who did this...its not my code, but I find it useful for my cutscene system with some modifications..I hope this can help you..its working well..

; Smooth 3rd person Camera Example
; ----------------

camdistance=5

Graphics3D 640,480 ;rem setup the Graphics mode

light=CreateLight() ;rem create a light for our scene

Global barney=CreateCube() ;rem create a cube and call it barney
Global obpiv=CreatePivot(barney) ; attach a pivot to barney
MoveEntity obpiv,0,0,-camdistance ; move the pivot back a little adjust this for effect

Global cam=CreateCamera() ;rem create a camera and make barney the cube it's parent entity


me=1
building=2
EntityType barney,me

Type brick ;rem create a type called brick with 1 field in it
Field entity ;rem create a field in type brick to hold the entity number
End Type

For x = 1 To 10 ;rem create 100 "bricks" To place in the world
For y = 1 To 10

b.brick = New brick ;rem add an entry into the type list b

b\entity = CopyEntity(barney) ;rem make a copy of barney and call it b\entity
EntityType b\entity,building
PositionEntity b\entity,x*8,0,y*8 ;rem make a grid

EntityColor b\entity,Rnd(0,255),Rnd(0,255),Rnd(0,255) ;rem random red,green,blue colors

Next
Next

Collisions me,building,3,1 ; set up collisions between me and the world

; main loop
While Not KeyDown( 1 )

If KeyDown (203) Then TurnEntity barney,0,1,0
If KeyDown(205) Then TurnEntity barney,0,-1,0
If KeyDown(200) Then speed#=speed#+.003
If KeyDown(208) Then speed#=speed#-.003

speed#=speed#*.99
MoveEntity barney,0,0,speed#

smoothcam(obpiv,barney,50)

; check for collisions and bounce if necessary
If CountCollisions ( barney )
hitentity=CollisionEntity ( barney,1 )
;change the color of the entity we hit
EntityColor hitentity,Rnd(0,255),Rnd(0,255),Rnd(0,255)
EndIf

If EntityCollided ( barney,building )
If speed#<0 Then speed#=speed# +.1
If speed#>0 Then speed#=speed# -.1
EndIf

UpdateWorld
RenderWorld ;rem render the world
Flip ; flip from the back buffer to the front buffer

Wend

End

Function smoothcam(pivot,target,camspeed)


curx#=EntityX(cam)
curz#=EntityZ(cam)
destx#=EntityX(pivot,True)
destz#=EntityZ(pivot,True)

curx#=curx#+((destx#-curx#)/camspeed)
curz#=curz#+((destz#-curz#)/camspeed)
cury#=3

PositionEntity cam,curx#,cury#,curz#

PointEntity cam,target
End Function


xmlspy(Posted 2005) [#7]
Here's something I got (utilizes some Mario camera code)

http://webzoom.freewebs.com/xmlspy/Downloads/Worlde.zip


callahan614(Posted 2005) [#8]
About camera collisions - I found myself on a tight timeframe to get a prototype finished of this 3D platformer I'm working on. Organic, fully enclosed corridor-based levels with plenty of twists and turns in them; to make a camera system rugged enough to stay smooth and on target without obscuring the player's view would have been far too much trouble, for a prototype at least.

What I did was request that my level designer (whom I love for doing this for me) make every surface in the level one-sided and ensure that all the normals faced in. She did that, and I imported the level and left collisions completely off my camera. All I did was limit the pitch(as the game uses 3rd person mouselook), and if the camera swings out - it goes through the wall; benefit of this is that the player can see IN through the one-sided wall, eliminating obscurity problems entirely.

This probably seems like a cheap solution to most of you, but it was quick, harmless, and combined with enough of a far clip to hide other segments of the level, provides a pretty decent feel. It also let me focus on the more important aspects, like my collision reponse...ugh.

I know this thread is a month old, but I thought this might be a helpful alternative to some of the more complex methods.