Smooth camera that doesn't stay behind the player

Blitz3D Forums/Blitz3D Beginners Area/Smooth camera that doesn't stay behind the player

Cubed Inc.(Posted 2010) [#1]
Once again, I apologize for all the posts, but this one is kinda interesting.

I'm trying to add a smooth camera into my game to add a better look becuase right now, the camera is as stiff as a board.

I knew from the start that there were tons of smooth camera examples, so I checked some out.

The only problem was that every smooth camera example that i've been able to find, the camera always stays behind the player( Tomb Raider style )

Is there any smooth camera example out there that doesn't have a camera that always stays behind the player?


jhocking(Posted 2010) [#2]
What exactly do you want the camera to smoothly do?


Cubed Inc.(Posted 2010) [#3]
jhocking
I'm trying to make the camera follow the player smoothly. I'm trying to find out how to create a smooth camera that follows the player, but doesnt always stay behind him all the time.

Last edited 2010

Last edited 2010


Matty(Posted 2010) [#4]
If it is following the player, how can it not remain behind him?


Or do you mean you want to be able to orbit around the player?

Or view from the side?

Or above?


Rob the Great(Posted 2010) [#5]
Show us one example that you've found. That will give us a better idea of what it is you're trying to do.


_PJ_(Posted 2010) [#6]
It should be possible to take the smooth camera code, which would rely on a pivot to which the camera is parented, and adjust the "preferrred state" of the camera position in relation to the pivot.

For example, using the example code I gave here: (It's not an auto-adjusting camera, but the principle's the same)
http://www.blitzbasic.com/Community/posts.php?topic=92546

The car is set at default location 0,0,0
and the initial state of the camera is set 10 units behind the car (and 1 unit up in the air) because it is first set as
MoveEntity Cam,0,1,-10					; Put some distance between the Camera and its Pivot (and therefore the Car too)



by modifying this to

MoveEntity Cam,0,10,0					; Put some distance between the Camera and its Pivot (and therefore the Car too)

The camera is placed directly above the car and so on...


Rob the Great(Posted 2010) [#7]
These are all brilliant 3rd person camera setups. Why couldn't I have seen this about 3 years ago, when I was making my camera code for the first time? lol.


Cubed Inc.(Posted 2010) [#8]
Rob the Great
The most well known example would probably be the castle example that came with blitz3d.

I'm almost confident that all of you have seen it. The camera is smooth, but the camera doesn't allow the character to have it's own rotations. The camera turns along with the player. I'm trying to learn how to create a smooth camera that doesn't turn with the player.


I hope I made it more clear, i'm not very good at explaining things -_-


Ross C(Posted 2010) [#9]
Place a pivot 10 units behind the player, and parent it to the player.

Every loop:
Point the camera at the pivot
move the camera towards the pivot, using the distance between the pivot and the camera : MoveEntity camera,0,0,entitydistance(player,pivot)*0.1
Point the camera at the player again

so something like this:

PointEntity camera,pivot
MoveEntity camera,0,0,EntityDistance(camera,pivot)*0.1
PointEntity camera,player

The pivot is the resting spot of the camera. Alter the *0.1 to affect how quickly the camera reaches the resting spot. This is the most basic smooth cam.

Last edited 2010


_PJ_(Posted 2010) [#10]

MoveEntity camera,0,0,EntityDistance(player,pivot)*0.1


Isn't this going to keep the camera moving away from the pivot? Until it's out of sight?

I would recommend keeping an 'ideal distance' such as:
Global IDEAL_DISTANCE#=10.0

So that in the loop you can ensure the camera gradually moves to wards this ideal distance point if it's ever 'dragged away':

PointEntity camera,pivot
dist=EntityDistance(player,pivot)
MoveEntity camera,0,0,((dist<IDEAL_DISTANCE)-(dist>IDEAL_DISTANCE))*0.1
PointEntity camera,pivot
PointEntity camera,player


If you don't want your camera to turn with the player, simply ensure that the rotation of the pivot is consistent, i.e. remove the TurnEntity CameraPivot... line

Last edited 2010


Ross C(Posted 2010) [#11]
Sorry Malice, well spotted. It's the distance between the camera and the pivot :)


jfk EO-11110(Posted 2010) [#12]
You don't have to point the camera to the pivot, nstead something like this is possible:
positionentity camera, entityx(camera)+(entityx(camera)-entityx(pivot))*0.2, entityy(camera),entityz(camera)+(entityz(camera)-entityz(pivot))*0.2
pointentity camera,player


Last edited 2010