-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistanceFromTarget.cs
More file actions
20 lines (19 loc) · 908 Bytes
/
DistanceFromTarget.cs
File metadata and controls
20 lines (19 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*********************************************************************
* Method 1 - Fast compile time method
* Returns the distance between Source and Target using .sqrMagnitude
* *******************************************************************/
float SqrMag_DistanceFromTarget(Transform Source, Transform Target)
{
float dist = (Target.position - Source.position).sqrMagnitude;
return dist;
}
/*************************************************************************
* Method 2 - Slower compile time method
* Returns the distance between Source and Target using Vector3.Distance()
* (Unity manuals) => Vector3.Dstance(a,b) is the same as (a,b).magnitude
* ***********************************************************************/
float Vector_DistanceFromTarget(Transform Source, Transform Target)
{
float dist = Vector3.Distance(Target.position, Source.position);
return dist;
}