Last active
May 30, 2018 08:43
-
-
Save unitycoder/b56bac0f780652a7acc4 to your computer and use it in GitHub Desktop.
Vector3.Dot()
This file contains 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; | |
using System.Collections; | |
public class dottest : MonoBehaviour { | |
public Transform p1; | |
public Transform p2; | |
public Transform p3; | |
public GUIText guiDOT; | |
void Update () | |
{ | |
Vector3 perpendicular = Vector3.Cross(p1.position-p2.position,Vector3.forward); | |
Vector3 targetDir = (p3.position-p1.position); | |
Debug.DrawLine(p1.position,p2.position,Color.gray); | |
Vector3 midpoint = Vector3.Lerp(p1.position,p2.position,0.5f); | |
Debug.DrawLine(midpoint,midpoint+perpendicular.normalized,Color.white); | |
float dotVal = Vector3.Dot(perpendicular.normalized,targetDir.normalized); | |
if (dotVal<0) | |
{ | |
Debug.DrawLine(p1.position,p3.position,Color.red); | |
Debug.DrawLine(p2.position,p3.position,Color.red); | |
}else{ | |
Debug.DrawLine(p1.position,p3.position,Color.green); | |
Debug.DrawLine(p2.position,p3.position,Color.green); | |
} | |
guiDOT.text = "DOT: "+dotVal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment