Guest User

Untitled

a guest
Dec 6th, 2025
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1. /// TrajectoryuData.cs
  2. /// Calculates trajectory data from start to target position
  3.     public static TrajectoryData CalculateTrajectory(
  4.         Vector3 start,
  5.         Vector3 target,
  6.         float speed,
  7.         float heightMultiplier,
  8.         float rotationSpeed,
  9.         int rotationDirection = 0)
  10.     {
  11.         float distance = Vector3.Distance(start, target);
  12.         float flightTime = ProjectilePhysics.CalculateFlightTime(distance, speed);
  13.         float maxHeight = ProjectilePhysics.CalculateArcHeight(distance, heightMultiplier);
  14.        
  15.         int rotDir = rotationDirection != 0 ? rotationDirection : (Random.value > 0.5f ? 1 : -1);
  16.        
  17.         return new TrajectoryData(start, target, flightTime, maxHeight, rotationSpeed, rotDir);
  18.     }
  19.  
  20. ---
  21. /// SkullTrajectory.cs
  22. void Update()
  23.     {
  24.         elapsedTime += Time.deltaTime;
  25.        
  26.         if (trajectoryData.IsComplete(elapsedTime))
  27.         {
  28.             CompleteThrow();
  29.             return;
  30.         }
  31.  
  32.         UpdatePosition();
  33.         UpdateRotation();
  34.         UpdateShadow();
  35.         UpdateCollider();
  36.     }
  37.  
  38.     private void UpdatePosition()
  39.     {
  40.         float progress = trajectoryData.GetProgress(elapsedTime);
  41.        
  42.         // Horizontal movement
  43.         basePosition = ProjectilePhysics.CalculateBasePosition(
  44.             trajectoryData.startPosition,
  45.             trajectoryData.targetPosition,
  46.             progress);
  47.  
  48.         // Vertical movement
  49.         currentHeight = ProjectilePhysics.CalculateHeight(
  50.             elapsedTime,
  51.             trajectoryData.verticalVelocity,
  52.             trajectoryData.gravity);
  53.  
  54.         // Final position
  55.         Vector3 finalPos = ProjectilePhysics.CalculatePosition(basePosition, currentHeight);
  56.         transform.position = finalPos;
  57.  
  58.         // Update depth sorting
  59.         if (depthSorting != null)
  60.         {
  61.             depthSorting.SetHeight(currentHeight);
  62.         }
  63.     }
  64.  
  65. ---
  66. /// ProjectilePhysics.cs
  67.     public static float CalculateFlightTime(float distance, float speed, float timeScale = 1f)
  68.     {
  69.         return Mathf.Lerp(0.5f * timeScale, distance / speed, distance / 10f);
  70.     }
  71.  
  72.  
  73.     public static float CalculateArcHeight(float distance, float heightMultiplier)
  74.     {
  75.         return distance * heightMultiplier;
  76.     }
  77.  
  78.  
  79.  public static Vector3 CalculatePosition(Vector3 basePosition, float height)
  80.     {
  81.         return basePosition + Vector3.up * Mathf.Max(0, height);
  82.     }
  83.  
  84.  
  85.     public static float CalculateGravity(float maxHeight, float flightTime)
  86.     {
  87.         float peakTime = flightTime * 0.5f;
  88.         return 2f * maxHeight / Mathf.Pow(peakTime, 2f);
  89.     }
  90.  
  91.  
  92.     public static Vector3 CalculateBasePosition(Vector3 start, Vector3 target, float progress)
  93.     {
  94.         return Vector3.Lerp(start, target, progress);
  95.     }
  96.  
  97. ---
  98. /// DepthSorting.cs
  99.     void LateUpdate()
  100.     {  
  101.        
  102.         if (spriteRenderer != null)
  103.         {
  104.             float groundY = transform.position.y;
  105.             int order = Mathf.RoundToInt(-(groundY - currentHeight) * 100f);
  106.             spriteRenderer.sortingOrder = order;
  107.         }
  108.     }
  109.  
  110.     public void SetHeight(float height)
  111.     {
  112.         currentHeight = height;
  113.     }
Advertisement
Add Comment
Please, Sign In to add comment