Hi, I’m coding a simple game and am having a problem with getting the character to move in the direction it is looking.
This is the coding for movefowards
void object3DS::MoveFowards(float amount)
{
mgPosition.x += mLookAt.x * amount;
mgPosition.y += mLookAt.y * amount;
mgPosition.z += mLookAt.z * amount;
}
Then in the render I use the characters rotation to change the lookat vector and the draw.
mLookAt.x = sin(mgRotation.z);
mLookAt.y = cos(mgRotation.z);
glTranslatef(mgPosition.x, mgPosition.y, mgPosition.z);
glRotatef(mgRotation.x, 1.0f, 0.0f, 0.0f);
glRotatef(mgRotation.y, 0.0f, 1.0f, 0.0f);
glRotatef(mgRotation.z, 0.0f, 0.0f, 1.0f);
it kind of works but the rotation isn’t perfect. The vector gets rotated too much so if I rotate the character in scene 30 degrees then the vector get changed by 70 degrees and the character strafes.
Could anyone help me please.