I'm trying to make a 3rd person camera, and so far it works. But when I try to look to the side, the camera just looks behind the player mode. I need it to rotate around the player model, but I can't seem to figure out how.
void UpdatePlayer(void)
{
int oldX = ( ( ( int ) ( dbCameraPositionX ( 0 ) - 50 ) / 100 ) + 1 );
int oldZ = ( ( ( int ) ( dbCameraPositionZ ( 0 ) - 50 ) / 100 ) + 1 );
int newX;
int newZ;
int iStrike; // which baddie has been hit
int iOldBaddieRotY; // used so we can face the baddie to the camera, blast him away and rotate back
int iLoop;
int scorchLoop = 0;
//dbControlCameraUsingArrowKeys ( 0 , 1 , 1 );
dbPositionMouse ( dbScreenWidth()/2 , dbScreenHeight()/2 );
if ( dbUpKey() || dbKeyState( 17 ) == 1 )
dbMoveObject ( 3 , PLAYERSPEED );
if ( dbDownKey() || dbKeyState( 31 ) == 1 )
dbMoveObject ( 3 , -PLAYERSPEED );
if ( dbLeftKey() || dbKeyState( 30 ) == 1 )
{
//dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) -90 );
dbMoveObject ( 3 , PLAYERSPEED );
//dbYRotateCamera ( 0 , dbObjectAngleY( 0 ) +90 );
}
if ( dbRightKey() || dbKeyState( 32 ) == 1 )
{
//dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) +90 );
dbMoveObject ( 3 , PLAYERSPEED );
//dbYRotateCamera ( 0 , dbObjectAngleY( 0 ) -90 );
}
if ( dbMouseClick() == 1 )
ShootGun();
// Udpate Gun
UpdateGun();
// Check for Reload
if (DoReload)
{
// Play Reload Animation
}
float cx = dbObjectPositionX ( 3 );
float cy = dbObjectPositionY ( 3 ) -40;
float cz = dbObjectPositionZ ( 3 );
float OldCamAngleY = dbCameraAngleY ( 0 );
float OldCamAngleX = dbCameraAngleX ( 0 );
CameraAngleY = dbWrapValue ( ( dbCameraAngleY ( 0 ) + dbMouseMoveX ( ) * 0.4f ) );
CameraAngleX = dbWrapValue ( ( dbCameraAngleX ( 0 ) + dbMouseMoveY ( ) * 0.4f ) );
if ( CameraAngleX > 80 && CameraAngleX <180 ) CameraAngleX = 80;
if ( CameraAngleX < 270 && CameraAngleX > 180 ) CameraAngleX = 270;
float fHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(3), dbObjectPositionZ(3) );
dbPositionObject(3, dbObjectPositionX(3), fHeight + 3.0f, dbObjectPositionZ(3));
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 3.0f, dbCameraPositionZ ( ) );
dbSetCameraToFollow(dbObjectPositionX(3), dbObjectPositionY(3), dbObjectPositionZ(3), dbObjectAngleY(3), 10, 5, 1, 0);
dbYRotateCamera ( 0 , dbCurveAngle ( CameraAngleY , OldCamAngleY , 6 ) );
dbXRotateCamera ( 0 , dbCurveAngle ( CameraAngleX , OldCamAngleX , 6 ) );
dbSetPointLight ( 0 , dbCameraPositionX ( 0 ) , 80 , dbCameraPositionZ ( 0 ) );
// Load Text
wsprintf ( czPlayText , "Health: %d " , Health );
dbText( 5 , 10 , czPlayText );
}