I'm building a topdown game with my main player rotating towards the mouse pointer but for some reason the player looks at the pointer from his right(his x axis) and i need need him to look from his Y.
I tried multiple ways and still the same as in i tried changing the vector from vector3 to vector2 but it will make things i don't need it to do, and i even tried using Quaternions.
void controlScheme()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.up * PlayerSpeed * Time.deltaTime,Space.World);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.down * PlayerSpeed * Time.deltaTime,Space.World);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * PlayerSpeed * Time.deltaTime,Space.World);
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * PlayerSpeed * Time.deltaTime,Space.World);
}
transform.up = dir;*/
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
the only weird thing that there is no code the tell the engine to make the player rotate towards the mouse from the player's right side.