Try – Boundaries Next
public void Simulate() { Vector2 vel0; Vector2 pos0; Vector2 attr_pos = Vector2.zero; Vector2 vel1; Vector2 pos1; float deltT = 0.005f; float C = 10; for (int j = 0; j < 10; j++) { vel0 = new Vector2(2, 0); pos0 = new Vector2(-3, 1); sSimulate.WriteLine(C.ToString()); sSimulate.WriteLine(" "); for (int i = 0; i < 1000; i++) { Vector2 attr_dir = (attr_pos - pos0).normalized; float attr_mag = (attr_pos - pos0).magnitude; vel1 = vel0 + attr_dir * (C / attr_mag) * deltT; pos1 = pos0 + vel1 * deltT; sSimulate.WriteLine(pos0.x.ToString("F6") + " , " + pos0.y.ToString("F6") + " , " + vel0.x.ToString("F6") + " , " + vel0.y.ToString("F6") + " , " + attr_mag.ToString("F6") + " , " + attr_dir.x.ToString("F6") + " , " + attr_dir.y.ToString("F6")); vel0 = vel1; pos0 = pos1; } C += 10; sSimulate.WriteLine(" "); sSimulate.WriteLine(" "); } sSimulate.Close(); }
Simulation_1