Im fairly new to dark GDK and i ran into a problem with my camera following an object (in this case a cube).
I wrote a code to move the cube with wasd (like in an fps) and look around with the mouse(the cube itself doesnt *look* up only the cam). Then i made the camera follow the cube but... here comes my problem:
it wont let me look left/right because the camera/cube tries to turn to the left/right but the cam has to center itself on the cube and it blocks itself that way so i cant look left/right.... it doesnt help with removing one of the lines which turns the cube/camera
hope somebody can help me out
heres the code:
float fCameraAngleX = dbWrapValue(dbCameraAngleX(2) + dbMouseMoveY() * 0.4f);
float fCameraAngleY = dbWrapValue(dbCameraAngleY(2) + dbMouseMoveX() * 0.4f);
float fObjPosX = dbObjectPositionX ( 2 ); //position of the object
float fObjPosY = dbObjectPositionY ( 2 );
float fObjPosZ = dbObjectPositionZ ( 2 );
if (dbKeyState(17) == true) //move forward with W
{
dbMoveObject(2,2);
}
if (dbKeyState(31) == true) //move backwards with S
{
dbMoveObject(2,-1);
}
if (dbKeyState(30) == true) //move left with A
{
dbMoveObjectLeft(2,2);
}
if (dbKeyState(32) == true) //move right with D
{
dbMoveObjectRight(2,2);
}
if(dbMouseMoveX){
dbXRotateCamera(2,fCameraAngleX); //rotate the (object and/or) camera up or down
//dbXRotateObject(2,fCameraAngleX);
}
if(dbMouseMoveY){
dbYRotateCamera(2,fCameraAngleY); //rotate the object and/or camera left or right
dbYRotateObject(2,fCameraAngleY); //this wont work because of the camera wants to follow the object
}
dbSetCameraToFollow ( 2, fObjPosX, 0fObjPosY, fObjPosZ, 360, 1, 1, 1, 1 );