// Update is called once per frame void Update() { Vector3 direction = Thruster.transform.forward; Vector3 force = Heading.transform.position - Thruster.transform.position; float costheta = Vector3.Dot(direction, force) / (direction.magnitude * force.magnitude); float theta = Mathf.Acos(costheta); if (theta > Mathf.PI) { theta -= Mathf.PI; } float degrees = theta * Mathf.Rad2Deg; float a = Mathf.Abs(theta); float p = a / Mathf.PI; float d = Mathf.Clamp(1 - p, 0, 1); float normal = MoreMaths.NormalDistribution(0.3f, 1, d) / (1.0f + (1.0f / 3.0f)); AngleText.text = $"{degrees} - {d} - {normal}"; Debug.DrawRay(transform.position, direction * 10, Color.blue); Debug.DrawRay(transform.position, direction * 10 * d, Color.red); Debug.DrawRay(transform.position, direction * 10 * normal, Color.green); }
// Update is called once per frame void FixedUpdate() { Vector3 delta = Target.position - transform.position; Vector3 velocity = body.velocity; Vector3 maxDeltaV = Force * Time.fixedDeltaTime / body.mass; Vector3 acceleration; if (velocity.sqrMagnitude == 0) { acceleration = Force; } else { acceleration = Vector3.ClampMagnitude(MoreMaths.Divide(-MoreMaths.Square(velocity), (2 * delta)), Force.magnitude); } body.AddForce(acceleration); text.text = $"Delta: {delta} - Velocity: {velocity} - Acceleration: {acceleration}"; }
private float CalculateEmissionFactor(Vector3 v) { Vector3 forward = transform.forward; // Find the angle between the target force and forward float costheta = Vector3.Dot(forward, v) / (forward.magnitude * v.magnitude); float theta = Mathf.Acos(costheta); if (theta > Mathf.PI) { theta -= Mathf.PI; } if (theta > -Mathf.PI && theta < Mathf.PI) { // Get the percentile between zero and PI float d = Mathf.Clamp(1 - (Mathf.Abs(theta) / Mathf.PI), 0, 1); // Normal distribution return(MoreMaths.NormalDistribution(0.2f, 1, d) / 2.0f); } return(0); }