using System;
using UnityEngine;
namespace Framework.Geometry {
/// Helper methods for calculating ballistic trajectories*
public static class Trajectory {
/*
private static Vector3 PlotTrajectoryAtTime (Vector3 start, Vector3 startVelocity, float time) {
return start + startVelocity*time + Physics.gravity*time*time*0.5f;
}
*/
/*
private static float getParabolaY(float width, float height, float x) {
float a = height / squared(width / 2.0f);
float b = height;
float c = width / 2.0f;
return (a * squared(x - c)) + b;
}
*/
/// Calculates the Y coordinate of a parabola from its X coordinate
/// Jump off velocity the parabola started with
/// X coordinate at which the Y coordinate should be calculated
/// The parabola's Y coordinate at the specified X coordinate
public static float GetParabolaY(float jumpOffVelocity, float x) {
return 0.5f * -Math.Abs(Physics.gravity.y) * squared(x) + (jumpOffVelocity * x);
}
/// Calculates the initial velocity required to reach a specific height
/// Height the trajectory should reach
/// The initial velocity required to reach the specified height
public static float GetJumpOffVelocity(float apexHeight) {
return Mathf.Sqrt(2.0f * Mathf.Abs(Physics.gravity.y) * apexHeight);
}
/// Calculates for how long a projectile will be airborne
/// Jump off velocity the projectile started from
/// The time until the projectile hits the ground again
public static float GetTimeInFlight(float jumpOffVelocity) {
return jumpOffVelocity / Math.Abs(Physics.gravity.y) * 2.0f;
}
/// Returns the square of the input value
/// Value that will be squared
/// The square of the specified value
private static float squared(float value) { return value * value; }
}
} // namespace Framework.Geometry