1
This commit is contained in:
@@ -24,9 +24,56 @@ namespace BITKit
|
||||
{
|
||||
return float.IsNaN(self.x) || float.IsNaN(self.y) || float.IsNaN(self.z) || float.IsNaN(self.w);
|
||||
}
|
||||
public static Quaternion AlignRotation(Quaternion rotation, float angleIncrement)
|
||||
{
|
||||
var eulerAngles = rotation.eulerAngles;
|
||||
|
||||
eulerAngles.x = Mathf.Round(eulerAngles.x / angleIncrement) * angleIncrement;
|
||||
eulerAngles.y = Mathf.Round(eulerAngles.y / angleIncrement) * angleIncrement;
|
||||
eulerAngles.z = Mathf.Round(eulerAngles.z / angleIncrement) * angleIncrement;
|
||||
|
||||
return Quaternion.Euler(eulerAngles);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public static partial class MathV
|
||||
{
|
||||
public static bool InFovRange(Vector3 selfPosition,Vector3 selfForward, Vector3 target, float fov)
|
||||
{
|
||||
var direction = target - selfPosition;
|
||||
var angle = Vector3.Angle(direction, selfForward);
|
||||
return angle < fov;
|
||||
}
|
||||
public static bool IsForward(Vector3 selfPosition, Vector3 selfForward,Vector3 targetPos)
|
||||
{
|
||||
// Get the direction from referencePos to targetPos
|
||||
Vector3 directionToTarget = (targetPos - selfPosition).normalized;
|
||||
|
||||
// Calculate the dot product
|
||||
float dotProduct = Vector3.Dot(directionToTarget, selfForward);
|
||||
|
||||
// If dot product is greater than 0, targetPos is in front of referencePos
|
||||
return dotProduct > 0;
|
||||
}
|
||||
|
||||
// 对于 Vector3
|
||||
public static Vector3 AlignRotation(Vector3 eulerAngles, float angleIncrement)
|
||||
{
|
||||
eulerAngles.x = Mathf.Round(eulerAngles.x / angleIncrement) * angleIncrement;
|
||||
eulerAngles.y = Mathf.Round(eulerAngles.y / angleIncrement) * angleIncrement;
|
||||
eulerAngles.z = Mathf.Round(eulerAngles.z / angleIncrement) * angleIncrement;
|
||||
|
||||
return eulerAngles;
|
||||
}
|
||||
public static Vector3 AlignToGrid(Vector3 position, float gridSize)
|
||||
{
|
||||
var x = Mathf.Round(position.x / gridSize) * gridSize;
|
||||
var y = Mathf.Round(position.y / gridSize) * gridSize;
|
||||
var z = Mathf.Round(position.z / gridSize) * gridSize;
|
||||
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
private static float CalculateMaxSpeed(this Vector2 direction)
|
||||
{
|
||||
var angle = Vector2.Angle(Vector2.right, direction);
|
||||
|
Reference in New Issue
Block a user