Alex_P
June 29, 2013, 10:15pm
1
Hello,
I’m trying to draw an object’s front arc line of sight for debugging purposes.
I’m using the following code.
void Update ()
{
Vector3 losRight = transform.TransformDirection(Quaternion.Euler(0, 45, 0) * transform.forward)*5;
Vector3 losLeft = transform.TransformDirection(Quaternion.Euler(0, -45, 0) * transform.forward)*5;
Debug.DrawRay(transform.position, losRight, Color.green);
Debug.DrawRay(transform.position, losLeft, Color.green);
}
I’m getting the correct result, pictured below, until the object rotates, at which point the rays begin to skew.
Any Idea how I can keep this front arc visual consistent?
I was also trying to implement the Handles.DrawSolidArc I found here , but with no luck. I know even less about javascript than I do about C# (fledgling programmer).
Any help would be greatly appreciated.
Thank You!
Zibber
June 29, 2013, 10:36pm
2
void Update()
{
float distance = 5f;
Debug.DrawRay(transform.position, (transform.forward + transform.right) * distance, Color.green);
Debug.DrawRay(transform.position, (transform.forward - transform.right) * distance, Color.green);
}
Zibber
June 29, 2013, 10:57pm
3
Here is an example using the Handles.DrawSolidArc in C#. First you must make a folder called ‘Editor’ and place the following script in it:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(SolidArcExample))]
public class DrawSolidArc : Editor
{
void OnSceneGUI()
{
SolidArcExample myTarget = (SolidArcExample)target;
Handles.color = new Color(1f, 1f, 1f, 0.2f);
Handles.DrawSolidArc(myTarget.transform.position,
myTarget.transform.up,
-myTarget.transform.right,
180,
myTarget.shieldArea);
Handles.color = Color.white;
myTarget.shieldArea = Handles.ScaleValueHandle(myTarget.shieldArea,
myTarget.transform.position + myTarget.transform.forward * myTarget.shieldArea,
myTarget.transform.rotation,
1f,
Handles.ConeCap,
1f);
}
}
You must then make the following script and place it as a component on the object that you want to have the arc.
using UnityEngine;
public class SolidArcExample : MonoBehaviour
{
public float shieldArea = 5f;
}