Camera Rotation

Blitz3D Forums/Blitz3D Beginners Area/Camera Rotation

Lordon(Posted 2004) [#1]
when the player rotates the camera, the camera and the character rotate seperately, so when you turn part way your see the side of the character, and when you turn all the way around and move forward, the character follows the camera. How do i make the camera rotate around the character?


Lordon(Posted 2004) [#2]
This is with Blitz3D btw


eBusiness(Posted 2004) [#3]
Const distance=10
PositionEntity camera,EntityX(character)+Sin(EntityYaw(character))*distance,EntityY(character)+0,EntityZ(character)-Cos(EntityYaw(character))*distance
RotateEntity camera,0,EntityYaw(character),0


I think you can make a similar effect using the characther as parent for the camera, I just think some plain math is more controllable.

By the way, welcome to the forum :)


Stevie G(Posted 2004) [#4]
If it's a chase style camera you could try something like this ... or look up the car demo in the samples directory.

;initialise
global target = createpivot( character )
positionentity target,0,0,-10
global camera = createcamera()
global smooth# = .05

function chase_camera()

  dx# = ( entityx(target,1) - entityx(camera) ) * smooth
  dy# = ( entityy(target,1) - entityy(camera) ) * smooth
  dz# = ( entityz(target,1) - entityz(camera) ) * smooth
  pointentity camera,character
  transalateentity camera,dx,dy,dz

end function



Rob Farley(Posted 2004) [#5]
You're missing adding the amount you want to turn the camera by additional to the yaw of the character

so..

sin(entityyaw(character)+extrarotate)
cos(entityyaw(character)+extrarotate)

Also I'd use a pointentity camera,character


Jeppe Nielsen(Posted 2004) [#6]
This piece of code will make a camera follow an entity at a specified speed. You can also specify where the camera should aim it's view, in relation to the entity.
Function followentity(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



Lordon(Posted 2004) [#7]
thanks a bunch guys, ill try it out =)