Rotate towards mouse pointer
I want to make an arrow rotate towards the mouse pointer, but instead it rotates towards the player character.
The player character has a camera tagged "MainCamera" on them.
public float speed = 5f;
private void Update()
{
Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
Debug.Log(direction);
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed * Time.deltaTime);
}
Comment
Best Answer
Answer by Pyrocreep · Sep 10, 2018 at 01:17 PM
Ive spent a days on this crap and it turns out its all because my camera perspective was set to projection instead of orthographic
Your answer
Follow this Question
Related Questions
Help with weapon rotation top down 2D C# 0 Answers
How do I control the camera with my mouse? 0 Answers
How do i limit the rotation of a game object in relation to a free following camera ? 0 Answers
Save player rotation in playerprefs c# 2 Answers
How can i make vertical and horizontal floats not return to 0 1 Answer