Hi all,
I've noticed that in my camera movement, when the camera/ player both walks forward/backward and strafes, the camera moves twice the amount as it should. At least that's what I think.
Below the code I'm using right now.
I have 2 questions:
- is my assumption correct that with the approach below, moving forward/backward + strafe at the same time, moves the camera/player twice the amount it should
- my approach to fix this, would be to check if the keys for both moving forward/backward and strafe and down, and if so, call a separate/ new function, moving the camera for strafe/ moving at once (if both keys down), if else only one etc.
What do you think?
if(_dinput.KeyDown(DIK_W)) _player.SetPosition(_d3dcam.MoveForwardBackward(_timer.GetDelta() * _player.GetWalkSpeed()));
if(_dinput.KeyDown(DIK_S)) _player.SetPosition(_d3dcam.MoveForwardBackward(_timer.GetDelta() * -_player.GetWalkSpeed()));
if(_dinput.KeyDown(DIK_A)) _player.SetPosition(_d3dcam.MoveLeftRight(_timer.GetDelta() * -_player.GetStrafeSpeed()));
if(_dinput.KeyDown(DIK_D)) _player.SetPosition(_d3dcam.MoveLeftRight(_timer.GetDelta() * _player.GetStrafeSpeed()));
// the actual camera functions
/**************************************************************************************/
/*** MOVE FORWARD BACKWARD ***/
/*** ==> usage: when camera moves forward or backward ***/
/*** ==> calculates the changed X and Z camera position, based on movement value ***/
/**************************************************************************************/
VECTOR3 CD3dcam::MoveForwardBackward(const float pAmount)
{
mPosition += mLook * pAmount; // 'flying' allowed, 6 DOF
// to disable 'FLYING', use:
// mPosition += D3DXVECTOR3(mLook.x, 0.0f, mLook.z) * pAmount;
return VECTOR3(mPosition.x, mPosition.y, mPosition.z);
}
/**************************************************************************************/
/*** MOVE LEFT RIGHT ***/
/*** ==> usage: when camera strafes to the left or right ***/
/*** ==> calculates the changed X and Z camera position, based on movement value ***/
/**************************************************************************************/
VECTOR3 CD3dcam::MoveLeftRight(const float pAmount)
{
mPosition += mRight * pAmount;
return VECTOR3(mPosition.x, mPosition.y, mPosition.z);
}