Question by
Wrynch · Jul 13, 2021 at 02:02 PM ·
rotation3dcontrollermousepositionshooter
3D Top Down shooter mouse follow inaccurate at some angles
Hi, I am making a top down shooter where the player rotates to the mouse position, but at certain angles, the character is off target, making inaccurate shots.
Player rotation code:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Plane gPlane = new Plane(Vector3.up, Vector3.zero);
float length;
if (gPlane.Raycast(ray, out length))
{
Vector3 pointToLook = ray.GetPoint(length);
Debug.DrawLine(ray.origin, pointToLook, Color.red);
transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
}
Player animator is not using Root Motion.
Shooting animation:
22b31c6a1b2fc17c6b15f4f21df8ec43.png
(53.8 kB)
Comment
Your answer
Follow this Question
Related Questions
How can I make my game object move like this? 0 Answers
Problems when rotating object to animate in Unity 1 Answer
Rotation on moving using virtual joystick is not working as expected in 3D game. 0 Answers
2D shooter: shoot towards cannon rotation 0 Answers
Finding Touching Faces Based on Rotation for Cubes in 3D 1 Answer