Rule of Thirds Camera Gizmo
I would like some help creating Gizmo for the camera that draws the rule of thirds on screen(Divide the screen into 9 sections). So far I have the following script attached to the main camera (but it always draws my test line way off the game camera)
var vStart : Vector3; function OnDrawGizmosSelected () {
Gizmos.color = Color.red;
vStart = transform.position;
vStart.x -= Screen.width /3;
Gizmos.DrawRay (vStart, Vector3.up * 55);
}
Answer by skovacs1 · Sep 24, 2010 at 09:42 PM
Would something like this work?
var screenOffset : float = 0.001;
function OnDrawGizmosSelected () { Gizmos.color = Color (1,0,0,.5);
//Figure out how big to make things
var zero = camera.ScreenPointToRay(Vector3(0,0,0)).GetPoint(screenOffset);
var right = camera.ScreenPointToRay(Vector3(Screen.width,0,0)).GetPoint(screenOffset);
var up = camera.ScreenPointToRay(Vector3(0,Screen.height,0)).GetPoint(screenOffset);
var upDirection = transform.up * (up - zero).magnitude;
var rightDirection = transform.right * (right - zero).magnitude;
//Get our points away from the screen
var bottomLeft =
camera.ScreenPointToRay(Vector3(Screen.width/3,0,0)).GetPoint(screenOffset);
var bottomRight =
camera.ScreenPointToRay(Vector3(2*Screen.width/3,0,0)).GetPoint(screenOffset);
var leftBottom =
camera.ScreenPointToRay(Vector3(0,Screen.height/3,0)).GetPoint(screenOffset);
var leftTop =
camera.ScreenPointToRay(Vector3(0,2*Screen.height/3,0)).GetPoint(screenOffset);
//Draw
Gizmos.DrawRay(bottomLeft, upDirection);
Gizmos.DrawRay(bottomRight, upDirection);
Gizmos.DrawRay(leftBottom, rightDirection);
Gizmos.DrawRay(leftTop, rightDirection);
}
Answer by $$anonymous$$ · Oct 14, 2016 at 03:06 PM
If you need in c#
public class RulesOfThirds : MonoBehaviour {
public bool enableGizmosRules = false;
public bool enableDebugRules = false;
public float screenOffSet = 0.001f;
private Camera cameraMain;
// Use this for initialization
void Start () {
cameraMain = GetComponent<Camera> ();
}
// Update is called once per frame
void Update () {
}
void OnDrawGizmosSelected(){
Gizmos.color = Color.yellow;
Vector3 zero = cameraMain.ScreenPointToRay (new Vector3 (0, 0, 0)).GetPoint (screenOffSet);
Vector3 right = cameraMain.ScreenPointToRay (new Vector3 (Screen.width, 0, 0)).GetPoint (screenOffSet);
Vector3 up = cameraMain.ScreenPointToRay (new Vector3 (0, Screen.height, 0)).GetPoint (screenOffSet);
Vector3 upDirection = transform.up * (up - zero).magnitude;
Vector3 rightDirection = transform.right * (right - zero).magnitude;
Vector3 bottomLeft = cameraMain.ScreenPointToRay (new Vector3 (Screen.width / 3, 0, 0)).GetPoint (screenOffSet);
Vector3 bottomRight = cameraMain.ScreenPointToRay (new Vector3 (2 * Screen.width / 3, 0, 0)).GetPoint (screenOffSet);
Vector3 RightTop = cameraMain.ScreenPointToRay (new Vector3 (0,Screen.height / 3, 0)).GetPoint (screenOffSet);
Vector3 LeftTop = cameraMain.ScreenPointToRay (new Vector3 (0, 2 * Screen.height / 3, 0)).GetPoint (screenOffSet);
if (enableDebugRules) {
Gizmos.DrawRay (bottomLeft, upDirection);
Gizmos.DrawRay (bottomRight, upDirection);
Gizmos.DrawRay (RightTop, rightDirection);
Gizmos.DrawRay (LeftTop, rightDirection);
}
if (enableDebugRules) {
Debug.DrawRay (bottomLeft, upDirection, Color.yellow);
Debug.DrawRay (bottomRight, upDirection, Color.yellow);
Debug.DrawRay (RightTop, rightDirection, Color.yellow);
Debug.DrawRay (LeftTop, rightDirection, Color.yellow);
}
}
}
Your answer
Follow this Question
Related Questions
Zooming in to a certain area of UI 0 Answers
Please help me with this error 2 Answers
Change shown scene from loaded scenes? 0 Answers
I want my camera to move only Y axis and my character to rotate with my camera 0 Answers
i am trying to work with wheel collides and i am having some problems 0 Answers