I have a rigidbody that I want to move with a mouse using Input.GetAxisRaw.
I know that Input.GetAxis is framerate independent but in my case it starts to move a lot faster at lower framerates. I have a suspicion that it is so because of the Rigidbody.MovePosition because it doesn't occur when I set the position directly. Dividing the mouse input by Time.DeltaTime does fix it but I'm not sure whether that's a good solution. Also I'm not sure whether that's related the input starts to get really jerky when the framerate is very high (~1000) and input sensitivity can get drastically different on different pc's.
My game is 2d with top down view.
Here's my code:
private void Update() { mouse_movement = GetMouseMovement(); } private void FixedUpdate() { Vector3 new_position = transform.position + mouse_movement; rigidbody.MovePosition(new_position); } public Vector3 GetMouseMovement() { Vector3 mouse_movement = new Vector3(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); return mouse_movement * MouseSensitivity; } Thanks in advance.
Time.deltaTime. So your game is framerate independent. You need toreturn mouse_movement * MouseSensitivity * Time.deltaTime. That's pretty standard.mouse_movementinFixedUpdateand not in plainUpdate, so you become fully frame rate independent :), cos fixedUpdate is called in a fixed intervall unlike Updatereturn mouse_movement * MouseSensitivity/(300f*Time.deltaTime);and doing everything in regularUpdateBut at higher framerates it starts stuttering (I guess that's because fps starts to jump up and down).