- Home /
Question by
AbdullrahmanAL-Zeidi · Oct 21, 2017 at 02:04 PM ·
rotation3dquaterniontopdownlookatmouse
Rotation Question in Top-down 3D Game
Hello everyone so recently i have been facing problems with top down 3d game rotation i couldn't fine a solution online sadly they all seem to give the same result so the problem is that after some character quick movements or some times fast rotations the character starts shaking (in the y axis) it fluctuates in about 5-10 degrees and i cant find the problem That being said i am changing the camera fov slightly during movement here is the code
private void CalculateRotation()
{
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
Vector3 dir = (Input.mousePosition - pos).normalized;
Vector3 rot = new Vector3 (0, (Mathf.Atan2 (dir.y, dir.x)) * -Mathf.Rad2Deg + 90f, 0);
transform.rotation = Quaternion.Euler (rot);
}
If any more information is needed i'l be glad to respond Thanks in advance :)
Comment