Here is very well commented code to create a decent 3rd person view.
(contains two functions)
void Create_Character ( unsigned int ModelNumber ) //you need to call this function once to create your player
{
dbLoadObject ( "H-GI-Idle.x", ModelNumber );//load player object, make sure 'H-GI-Idle.x' is in your project folder
dbPositionObject ( ModelNumber, 0, 3, 0 );//position player object
dbRotateObject ( ModelNumber, 0, 0, 0 );//rotate player object
dbSetObjectSpeed ( ModelNumber, 30 );//set player object animation speed
dbLoopObject ( ModelNumber );//start looping player object animation
dbMakeObjectSphere ( 99, 1 );//make the object that follows the player, the camera follows this object
dbScaleObject ( 99, .0001, .0001, .0001 );//scale it out of view
dbPositionObject ( 99, dbObjectPositionX(ModelNumber), dbObjectPositionY(ModelNumber) + 500, dbObjectPositionZ(ModelNumber) );//position it where it goes
}
void Camera_Control ( unsigned int ModelNumber ) //call this function once every frame to have the right-click view work
{
int beforeclick1 = dbMouseMoveX();
int beforeclick2 = dbMouseMoveY();
if ( dbMouseClick() == 2 )//if user clicked the right mouse button
{
dbHideMouse();//hide mouse
dbXRotateObject ( 99, dbObjectAngleX(99) - (dbMouseMoveY() - beforeclick2)/4.0f );//rotate the object that follows player up and down if that was changed
dbYRotateObject ( ModelNumber, dbObjectAngleY(ModelNumber) - (dbMouseMoveX() - beforeclick1)/4.0f );//rotate the player object left and right if that was changed
}
dbPositionObject ( 99, dbObjectPositionX(ModelNumber), dbObjectPositionY(ModelNumber) + 2, dbObjectPositionZ(ModelNumber) );//move the object that follows the character
dbPositionCamera ( dbObjectPositionX(99), dbObjectPositionY(99), dbObjectPositionZ(99) );//move the camera to the object that follows the character
dbRotateCamera ( dbObjectAngleX(99), dbObjectAngleY(ModelNumber) + 180, dbObjectAngleZ(99) );//rotate the camera to the object that follows the character
dbMoveCamera ( -5 );//move the camera out
if ( dbMouseClick() != 2 )//if user didn't click the right mouse button
{
dbShowMouse();//show mouse
}
}
I hope that works for anyone who needs it, if there are bugs I missed feel free to post!