can't figure out top down 2D rotation (noob)
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;
void Start()
{
}
void Update()
{
x = Input.mousePosition.x;
y = Input.mousePosition.y;
Vector2 mousePos = (new Vector2(Input.mousePosition.x, Input.mousePosition.y));
Debug.Log(mousePos);
transform.LookAt(mousePos);
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotating weapon in top-down 2D 0 Answers
2D TopDown rotating a gun according to its parent position, ON MOBILE, not PC, 0 Answers
2D Sprite issue when rotating towards mouse click location. 2 Answers
how to make this top down 2d car drift right. 0 Answers
Topdown 2D Colliders Not Working, help! 0 Answers