using Godot; namespace ColdMint.scripts.utils; /// /// ParabolicUtils /// 抛物线工具 /// public static class ParabolicUtils { /// /// Calculated parabola /// 计算抛物线 /// /// ///Origin of coordinates ///坐标的原点 /// /// ///speed ///速度 /// Represents the distance traveled per second /// 表示每秒移动的距离 /// /// ///gravity ///重力 /// /// ///Sampling step size ///采样步长 /// How many seconds to take a point /// 多少秒取一次点 /// /// public static Vector2[] ComputeParabolic(Vector2 origin, Vector2 velocityVector, float gravity, float steps) { // 计算采样点数量 var numSteps = Mathf.CeilToInt(1f / steps); // 初始化结果数组 var points = new Vector2[numSteps]; // 计算每个采样点的位置 for (var i = 0; i < numSteps; i++) { // 计算当前时间 var t = i * steps; // 计算当前位置 var x = origin.X + velocityVector.X * t; var y = origin.Y + velocityVector.Y * t + 0.5f * gravity * t * t; // 将位置添加到结果数组中 points[i] = new Vector2(x, y); } return points; } }