Hello, i am a noob and have been trying for the whole day now and have gotten nowhere in this area.
’
This is the (mostly base) rotate script which i put into a separate script to be called in the player controller. (The actual mouse facing code is from indie nuggets on youtube.)
’
(Sidenote: Is there any nifty way i can use logical operators or compare vector3s?
Something like v1 > v2 or v1.y > v2.y–or something like that?)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseTracking : MonoBehaviour{
private static PlayerController playerObject = PlayerController.Instance;
public static float allowAimRadius = 1f;
public static void ShipAim2D()
{
Vector3 vAimRadius = new Vector3(allowAimRadius, allowAimRadius, 0);
Vector3 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(playerObject.transform.position);
float angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) - 90;
playerObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}