- Home /
Other
Vector3 position changing without force being applied in the direction
Hello,
I'm working on player movement right now, attempting to move a character using its rigidbody, as such:
if (Input.GetKeyDown("w"))
{
transform.rotation = Quaternion.Euler(0, -180, 0);
playerRigid.AddForce(1, 4, 0, ForceMode.VelocityChange);
}
And the character does move in the specified direction properly, however, with this example, the Z position moves ever-so-slightly, according to the Inspector. It's not visible in the game, however the changing builds up and is affecting other aspects concerning my character's current position.
Any ideas on why this might be happening? Any help would be appreciated and I can supply more details if need be.
Thank you, A lost dev
Answer by naenae_nz · Jun 07, 2020 at 03:43 AM
This is likely due to floating point precision errors, they are very small, and there is nothing you can do about them. Also, are you sure you shouldn't be doing`if (Input.GetKey(Keycode("w")))`?