Hi, new here. I'm trying to create a top down 2D game but I am already stumped on how to get the rotation working so the player looks at the cursor, can't find the answer anywhere on the forums, thanks in advance for all help.
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour
private float x;
private float y;
x = Input.mousePosition.x;
y = Input.mousePosition.y;
Vector2 mousePos = (new Vector2(Input.mousePosition.x, Input.mousePosition.y));
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
151 People are following this question.
2D Sprite issue when rotating towards mouse click location.
Parenting an object causes it to change rotation
Sprites only rotate by 90 degrees
2D rotation problem
i have created a wheel and added the rotation now its rotating in the anticlockwise direction,how can it made to be rotated in the clockwise direction