I have to deal with the feared 180°-0° and back problem. I need the results of the angle in 360° degrees but have +180° 0° then back on the same side as the compass indicator makes it hard to find the target that way-lol
Also I noticed that the target indicator stays to only one side of the compass.
0° on the compass is 180° in the script, 180° on the compass is 0° in the script
All on the left side (180° to 360°) of the compass and never the full 0° to 360° around the compass perimeter.
using UnityEngine;
using System.Collections;
public class Target_Indicator : MonoBehaviour
{
public Transform target; //Object that will be set in the Inspector.
public Transform indicatorPlane; // Drag the indicator here
public float angle = 0; //Create sting, Now we can see it in the inspector.
void Update()
{
Vector3 targetDir = target.position - transform.position;
Vector3 forward = transform.forward;
targetDir.y = 0; // Remove any height difference
angle = Vector3.Angle(targetDir, forward);
indicatorPlane.eulerAngles = new Vector3(0, angle, 0);
}
void OnGUI()
{
float displayValue = Mathf.Round(angle);//Change decimal to hole numbers.
//Make a GUI label - position on sccreen - add "angle:" - display the value.
GUI.Label(new Rect(30, 475, 150, 50), "angle: " + displayValue.ToString());
}
}
I’ve seen other posts but the use a different structure than mine.
One noted how to change to -180° 0° +180°, but again, I need 360°
It would stand to reason that when one works with rotation, the program whould display
0° to 360° or a option the of.
C# helllllp
Rick