Last active
March 13, 2023 13:30
-
-
Save barleymalt/c114abf1690775b1c7d8843424d68d92 to your computer and use it in GitHub Desktop.
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
public static class Vector3Extensions | |
{ | |
public static Vector3 GetPointOnSphereAngle(this Vector3 center, Vector3 targetDirection, float angle, float radius) | |
{ | |
float angleInRad = Random.Range(0.0f, angle) * Mathf.Deg2Rad; | |
Quaternion dir = Quaternion.LookRotation(targetDirection - center); | |
Vector2 pointOnCircle = (Random.onUnitSphere) * Mathf.Sin(angleInRad); | |
Vector3 pointOnSphere = dir * (new Vector3(pointOnCircle.x, pointOnCircle.y, Mathf.Cos(angleInRad))) + center; | |
Vector3 distFromCenter = (pointOnSphere - center) * radius; | |
return pointOnSphere + distFromCenter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment