Created
June 26, 2025 06:44
-
-
Save robochase6000/fbcd2f94db04a9b87ecb2173be455099 to your computer and use it in GitHub Desktop.
Dot & Projection visualization test in unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| namespace RC6 | |
| { | |
| public class DotTest : MonoBehaviour | |
| { | |
| public LineRenderer Line_Forward; | |
| public LineRenderer Line_Diff; | |
| public LineRenderer Line_Dir; | |
| public LineRenderer Line_Dot; | |
| public LineRenderer Line_DotNormal; | |
| public LineRenderer Line_Project; | |
| public Transform Looker; | |
| public Transform Target; | |
| void Update() | |
| { | |
| DrawLine(Line_Forward, Looker.position, Looker.position + Looker.forward, 0f); | |
| var diff = Target.position - Looker.position; | |
| DrawLine(Line_Diff, Looker.position, Looker.position + diff, 0.1f); | |
| var diffNorm = diff.normalized; | |
| DrawLine(Line_Dir, Looker.position, Looker.position + diffNorm, 0.2f); | |
| var dot = Vector3.Dot(Looker.forward, diff); | |
| DrawLine(Line_Dot, Looker.position, Looker.position + Looker.forward * dot, 0.3f); | |
| var dotNorm = Vector3.Dot(Looker.forward, diffNorm); | |
| DrawLine(Line_DotNormal, Looker.position, Looker.position + Looker.forward * dotNorm, 0.4f); | |
| var project = Vector3.Project(diff, Looker.right); | |
| DrawLine(Line_Project, Looker.position, project, 0.5f); | |
| } | |
| void DrawLine(LineRenderer lineRenderer, Vector3 a, Vector3 b, float y) | |
| { | |
| a.y = y; | |
| b.y = y; | |
| lineRenderer.SetPosition(0, a); | |
| lineRenderer.SetPosition(1, b); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment