Hello,
I'm creating a third person game, and i want the camera to move around my player-model, but it moves only around itself, so the player dissapears from the screen.
Here is the code i use at the moment:
float PLAYERSPEED = 3.5f;
float OldCamAngleY;
float OldCamAngleX;
float CameraAngleY;
float CameraAngleX;
////////////////////////////////////
void updatePlayer()
{
int oldX = ( ( ( int ) ( dbCameraPositionX ( 0 ) - 50 ) / 100 ) + 1 );
int oldZ = ( ( ( int ) ( dbCameraPositionZ ( 0 ) - 50 ) / 100 ) + 1 );
int newX;
int newZ;
int iLoop;
int scorchLoop = 0;
dbPositionMouse ( dbScreenWidth()/2 , dbScreenHeight()/2 );
if ( dbUpKey() || dbKeyState( 17 ) == 1 )
{
dbMoveCamera ( 0 , PLAYERSPEED );
dbYRotateObject ( 3 , dbCameraAngleY( 0 ) + 180 );
dbMoveObject ( 3 , PLAYERSPEED );
}
if ( dbDownKey() || dbKeyState( 31 ) == 1 )
{
dbMoveCamera ( 0 , -PLAYERSPEED );
dbYRotateObject ( 3 , dbCameraAngleY( 0 ) -0 );
dbMoveObject ( 3 , PLAYERSPEED );
}
if ( dbLeftKey() || dbKeyState( 30 ) == 1 )
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) -90 );
dbYRotateObject ( 3 , dbCameraAngleY( 0 ) -90 );
dbMoveCamera ( 0 , PLAYERSPEED );
dbMoveObject ( 3 , PLAYERSPEED );
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) +90 );
dbYRotateObject ( 3 , dbCameraAngleY( 0 ) +90 );
}
if ( dbRightKey() || dbKeyState( 32 ) == 1 )
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) + 90 );
dbYRotateObject ( 3 , dbCameraAngleY( 0 ) +90 );
dbMoveCamera ( 0 , PLAYERSPEED );
dbMoveObject ( 3 , PLAYERSPEED );
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) -90 );
dbYRotateObject ( 3 , dbCameraAngleY( 0 ) -90 );
}
float cx = dbCameraPositionX ( 0 );
float cy = dbCameraPositionY ( 0 ) -40;
float cz = dbCameraPositionZ ( 0 );
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;
dbYRotateCamera ( 0 , dbCurveAngle ( CameraAngleY , OldCamAngleY , 6 ) );
dbXRotateCamera ( 0 , dbCurveAngle ( CameraAngleX , OldCamAngleX , 6 ) );
dbPositionCamera ( 0 , dbCameraPositionX ( 0 ) , 40 , dbCameraPositionZ ( 0 ) );
dbSetPointLight ( 0 , dbCameraPositionX ( 0 ) , 80 , dbCameraPositionZ ( 0 ) );
}
.
.
.
In the main Loop I use this:
while ( LoopGDK ( ) )
{
updatePlayer();
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
dbPositionObject ( 3, dbCameraPositionX ( ) , fHeight + 0.1f, dbCameraPositionZ ( ) +60.0f );
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 95.0f, dbCameraPositionZ ( ) );
.
.
.
What do I have to change?
All other stuff is working correctly, the player turns around etc.
kind regards
MES