Skip to content

Commit b41dd6b

Browse files
committed
feat(Util): Add point in direction
1 parent 2167d02 commit b41dd6b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Assets/JCSUnity/Scripts/JCS_Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ namespace JCSUnity
1515
public static class JCS_Constants
1616
{
1717
public static float GRAVITY = -9.81f;
18-
1918
}
2019
}

Assets/JCSUnity/Scripts/Util/JCS_Vector.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ namespace JCSUnity
1515
/// </summary>
1616
public static class JCS_Vector
1717
{
18+
/* Variables */
19+
20+
// Distance to look in direction to get the point.
21+
public const float LOOK_DISTANCE = 10.0f;
22+
23+
/* Setter & Getter */
24+
25+
/* Functions */
26+
1827
/// <summary>
1928
/// Set the vector value.
2029
/// </summary>
@@ -369,5 +378,19 @@ public static bool InDistance(Vector3 pos1, Vector3 pos2, float threshold)
369378
float distance = Vector3.Distance(pos1, pos2);
370379
return (distance <= threshold);
371380
}
381+
382+
/// <summary>
383+
/// Return the point in specific direction.
384+
/// </summary>
385+
public static Vector3 PointInDirection(JCS_Vector3Direction direction, Transform trans)
386+
{
387+
return PointInDirection(direction, trans, LOOK_DISTANCE);
388+
}
389+
public static Vector3 PointInDirection(JCS_Vector3Direction direction, Transform trans, float distance)
390+
{
391+
Vector3 dir = Direction(direction, trans);
392+
393+
return trans.position + dir * distance;
394+
}
372395
}
373396
}

docs/ScriptReference/Util/JCS_Vector.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ Vector utilities.
1919
| LookDegree | How close player looks toward the target. |
2020
| SignedLookDegree | How close player looks toward the target. |
2121
| InDistance | Check if distance between pos1 and pos2 is under the threshold. |
22+
| PointInDirection | Return the point in specific direction. |

0 commit comments

Comments
 (0)