using Godot; using System; public partial class Line2d : Line2D { private TestScene Test { get; set; } public Vector2 Start => Test.A.Position; public Vector2 End => Test.B.Position; public float CurveRate { get; set; } = 20; public int CDir { get; set; } = 1; private void MakeCurve(float curveRate=20f, int cDir = 1) { Vector2[] xs = new Vector2[17]; int[] x2 = new[] { 4, 12 }; int[] x3 = new[] { 2, 6, 10, 14}; int[] x4 = new[] { 1, 3, 5, 7, 9, 11, 13, 15 }; Vector2 vd = End - Start; Vector2 nor = vd.Rotated(Mathf.Pi / 2 * cDir); Vector2 center = vd / 2 + 4f * nor / curveRate; xs[0] = Start; xs[16] = End; xs[8] = center + xs[0]; foreach (int i in x2) { Vector2 v = xs[i + 4] - xs[i - 4]; Vector2 n = v.Rotated(Mathf.Pi / 2 * cDir); Vector2 w = v / 2 + 2f * n / curveRate; xs[i] = w + xs[i - 4]; } foreach (int i in x3) { Vector2 v = xs[i + 2] - xs[i - 2]; Vector2 n = v.Rotated(Mathf.Pi / 2 * cDir); Vector2 w = v / 2 + n / curveRate; xs[i] = w + xs[i - 2]; } foreach (int i in x4) { Vector2 v = xs[i + 1] - xs[i - 1]; Vector2 n = v.Rotated(Mathf.Pi / 2 * cDir); Vector2 w = v / 2 + n / curveRate; xs[i] = w + xs[i - 1]; } Points = xs; } private void T() { Points = new[] { new Vector2(1, 1), new Vector2(2, 3) }; GD.Print(Points.Length); } // Called when the node enters the scene tree for the first time. public override void _Ready() { Test = GetParent(); GD.Print("Ready"); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { //T(); MakeCurve(CurveRate, CDir); } }