- Home /
Question by
NerdRageStudios · May 09, 2017 at 09:14 AM ·
rotationmovementvsync
Jerky movement on rotation when vSync enabled
Hi, I'm getting some weird jerky movement on the character when vysnc enabled, but ONLY when rotating whilst moving. Its a top down 2D game.
I have tried using Time.DeltaTime, but it makes no difference.
Here is the code I use for movement and rotation.
void FixedUpdate()
{
MovePlayer();
RotatePlayer();
}
void MovePlayer()
{
Vector2 inputVector = new Vector2(_player.GetAxis("Horizontal"), _player.GetAxis("Vertical"));
_rigidbody.AddForce(inputVector.normalized * Ref.playerManager.currentMoveSpeed, ForceMode2D.Force);
}
void RotatePlayer()
{
float AngleRad = Mathf.Atan2(GetWorldPositionOnPlane(Input.mousePosition, 0).y - transform.position.y, GetWorldPositionOnPlane(Input.mousePosition, 0).x - transform.position.x);
angle = (180 / Mathf.PI) * AngleRad - 90f;
Quaternion _newRot = Quaternion.Lerp(transform.rotation, Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, angle), Ref.playerManager.currentRotationSpeed);
transform.rotation = _newRot;
}
public Vector3 GetWorldPositionOnPlane(Vector3 screenPosition, float z)
{
Ray ray = Camera.main.ScreenPointToRay(screenPosition);
Plane xy = new Plane(Vector3.forward, new Vector3(0, 0, z));
float distance;
return ray.GetPoint(distance);
}
With Vsync disabled, the game is buttery smooth, but enabled the main character moves smooth, until you rotate while moving, then it goes all jerky.
Any ideas what's causing the jerkiness in the rotation code?
cheers!
Comment
This also happens if I disable vsync and just limit the framerate to 60
Your answer
Follow this Question
Related Questions
Rotating Character 1 Answer
Rotate an object such that it is theta degrees relative to another object 1 Answer
Random insect movement 1 Answer
Look Where You're Going 3 Answers