- Home /
Question by
agentsmith · Jul 01, 2010 at 12:48 AM ·
gizmosgizmofov
Gizmo question: How do I create a field of view using gizmos?
I thought maybe I can draw two vectors based off of the character's transform.forward vector (one vector on each side of the transform.forward vector). For example, how would I draw vectors 70 degrees from transform.forward? The middle line represents transform.forward and the two angle lines represent the 70 degree vectors: " \ | / "
var rayRange = 10;
function OnDrawGizmosSelected ()
{
Gizmos.color = Color.magenta;
Gizmos.DrawRay (transform.position, transform.forward * rayRange);
}
Thanks!
Comment
Don't use HT$$anonymous$$L in your post unless you absolutely know how to use it. There's a Code Format button on the toolbar for a reason.
Best Answer
Answer by Tetrad · Jul 01, 2010 at 01:10 AM
Try using Quaterion.AxisAngle to create a rotation.
So, something like this:
void OnDrawGizmosSelected()
{
float totalFOV = 70.0f;
float rayRange = 10.0f;
float halfFOV = totalFOV / 2.0f;
Quaternion leftRayRotation = Quaternion.AngleAxis( -halfFOV, Vector3.up );
Quaternion rightRayRotation = Quaternion.AngleAxis( halfFOV, Vector3.up );
Vector3 leftRayDirection = leftRayRotation * transform.forward;
Vector3 rightRayDirection = rightRayRotation * transform.forward;
Gizmos.DrawRay( transform.position, leftRayDirection * rayRange );
Gizmos.DrawRay( transform.position, rightRayDirection * rayRange );
}
Wow, Awesome! It looks beautiful; thanks Tetrad!!!!!!!