🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Player slowly drifting backwards when strafing

Started by
2 comments, last by judeclarke 3 years, 12 months ago

I am calculating my strafing direction with a rotation of (0, 0, 0) with the following steps below. The resulting movement that I get is (-0.999999702, 0.0, -0.000796274282), which is close, however, given that my rotation is (0, 0, 0) I should really be getting (1.0, 0.0, 0.0). I understand why this is happening due to floating point but I don't understand how to prevent the following issue. When I apply my movement to the character, the z value will slowly drift backwards as the z is being decremented. How could I prevent something like this?

   Vector3 movement;
   movement.x = -sin(transform->GetRotation().x + (90.0f * (3.14f / 180)));
   movement.y = 0.0f;
   movement.z = -cos(transform->GetRotation().z + (90.0f * (3.14f / 180)));

   plyer.Movement += ((movement * character.StrafeSpeed) * dt);

Advertisement

Simply use more digits of PI. See for your self: https://ideone.com/sKatL5

@fastcall22 A perfect and simple solution, I did not think of that

This topic is closed to new replies.

Advertisement