camera Pivots

Blitz3D Forums/Blitz3D Programming/camera Pivots

cash(Posted 2004) [#1]
Sorry about this, the flipmesh post earlier can be ignored as it was something I was trying in order to solve a problem, but I think I am going to have to do it "Properly" .

Anyway, I know this has probably been asked before, but a little guidance would be appreciated.

I have a Third Person Shooter which to date all works except I am not happy with the basic camera function. Put simply, the camera is parented to the player, and it located very close to the player.

What I really want to do is have the camera further away so I can see the entire figure of the player, but as you can guess, the camera passes through walls and the wall in turn blocks view of the player.

If I use a collision on the camera, then when it hits the wall, everything goes out of sync and the man moves one way while the camera slides along the wall etc.

From reading previous posts I assume this can be fixed using pivots, but I could do with a basic outline of how to do this.

What I am thinking is 2 pivots, one for the camera one for the man, and somehow having the man placed between the two
and then having the camera pointing at the other mmanpivot.

Has anyone got any tips for this. I am not interested in anything too clever, just the ability to view the player from a further camera distance.


Ross C(Posted 2004) [#2]
Hmmm...i think you don't need pivots. Try this.

Set the camera to the players position. Rotate the camera to the players rotation, then move it back 5 units ( or whatever distance your wanting). And finally point the camera at the player. Do this every loop :) Should do the trick.


cash(Posted 2004) [#3]
Ross

Thanks for that, i`ll give it a go. Will it be a problem tha the camera will be behind the player, when it uses pointentity. I am not able to test this at the moment, just a thought.


Ross C(Posted 2004) [#4]
Well, what will happen is you need to place the camera at the player position and rotation, because the collision will knock off it position.

So once it's been set the players position/rotation, your moving it directly back from the player, and it will slide along a wall. So it won't be pointing at the player anymore. So you use pointentity :) Pointentity will just make the camera look at the player :)


Jeppe Nielsen(Posted 2004) [#5]
This piece of code, allows you to make a camera follow an entity, at given coordinates in relation to the entity. It also lets you set where the camera should look at, plus a smoothing parameter, that allows you to set how smooth the camera should move:

;make the camera follow the entity, behind and above:
Followcamera(camera,entity,0,4,-4)

Function Followcamera(camera,entity,camx#,camy#,camz#,aimx#=0,aimy#=0,aimz#=0,smoothcam#=0.1,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


Hope it is of any use.


cash(Posted 2004) [#6]
Jeppe Nielsen

Thanks for the code, I modified it a bit so the pitch and roll were fixed and it works great in my game. Thanks a lot.