Hello,
My current code is moving particles in a straight line. The goal is simulate their movement through a magnetic and electric field depending on many variables. I will worry about the scaling later on when the physics are working properly. I provided my current coding for this scripted movement and a list of equations that are being used within it. The last picture is the goal that my simulation is working towards. The arcs within the movement is caused by a magnetic field turning a particles path in a circular motion. My simulation is within 3D space. I linked the images within a comment below.
I appreciate any input! Thanks!
float Radius;
public Rigidbody rb;
public float Constant;
public float Charge;
public float B;
float P;
public float Px;
public float py;
public float Pz;
float Omega;
float Velocity;
float time;
float delta_time;
public float delta_min;
public float delta_max;
float px_dt;
float pz_dt;
private void Start()
{
rb = GetComponent<Rigidbody>();
time = Time.deltaTime;
P = Mathf.Sqrt(Mathf.Pow(Px, 2) + Mathf.Pow(Pz, 2));
Radius = (Constant * P) / (B * rb.mass);
Velocity = P / rb.mass;
Omega = Velocity / Radius;
}
private void FixedUpdate()
{
delta_time = Mathf.Lerp(delta_min, delta_max, time);
px_dt = Mathf.Cos(Omega * delta_time) * Px * time + Mathf.Sin(Omega * delta_time) * Pz * time;
pz_dt = -Mathf.Sin(Omega * delta_time) * Px * time + Mathf.Cos(Omega * delta_time) * Pz * time;
transform.Translate(px_dt, py, pz_dt);
}
}