MathHelper.cs 628 B

123456789101112131415161718192021
  1. using UnityEngine;
  2. public static class MathHelpers
  3. {
  4. public static float PerlinNoise2D(float x, float y, float scale)
  5. {
  6. return Mathf.PerlinNoise(x / scale, y / scale);
  7. }
  8. public static float CalculateSlope(Vector3 pointA, Vector3 pointB)
  9. {
  10. return Mathf.Abs(pointB.y - pointA.y) / Vector3.Distance(pointA, pointB);
  11. }
  12. public static Vector3 GetRandomPointInRange(Vector3 center, float range)
  13. {
  14. float x = Random.Range(center.x - range, center.x + range);
  15. float z = Random.Range(center.z - range, center.z + range);
  16. return new Vector3(x, center.y, z);
  17. }
  18. }