Calculating Torque Needed to Travel a Certain Distance Via the Magnus Effect
Aight so I've been at this for several days and with how much it's slowing the project down I've made the hard decision to come beg the internet. I'm working on a physics-based golf game in Unity and am working on implementing the magnus effect. This is my calculation for tangential force based on torque per physics step:
float _BallRadius = .0427f;
float _halfmass = Mathf.Sqrt(_BallRadius*.5f );
Vector3 _av = new Vector3(GetComponent<Rigidbody>().angularVelocity.y, 0, GetComponent<Rigidbody>().angularVelocity.z);
Vector3 _v = Vector3.Scale(GetComponent<Rigidbody>().velocity.normalized,(new Vector3(GetComponent<Rigidbody>().velocity.x, 0, GetComponent<Rigidbody>().velocity.z)));
float _vv = new Vector3(GetComponent<Rigidbody>().velocity.x, 0, GetComponent<Rigidbody>().velocity.z).magnitude;
float _mag = ((1.429f * Mathf.Abs(_vv)* (2 * Mathf.PI * _halfmass * _av.x))) * (_BallRadius * .5f);
Vector3 _xmagdir = new Vector3(GetComponent<Rigidbody>().velocity.x, 0, GetComponent<Rigidbody>().velocity.z);
GetComponent<Rigidbody>().AddForce(Vector3.Cross(_xmagdir.normalized,Vector3.up)*_mag, ForceMode.Acceleration);
This works well enough, but now I need to figure out the correct amount to give the ball to get this result, wherein given a formula for force over time based on torque, an initial torque is set such that by the end of a time calculated from horizontal range and velocity, the projectile's velocity in the tangent direction is equal to negative its tangent velocity at the start:
I've tried several different approaches, and I've come to the conclusion that this is mostly comes down to trigonometry. Here is where I'm at currently (this is before the tangential direction is applied to the final velocity vector):
Vector3 GetMagnusTorque(float Distance, Vector3 V_BallForce, float xdir)
{
float _BallRadius = .0427f;
float _halfmass = Mathf.Sqrt(_BallRadius*.5f);
Vector3 v = GO_Camera.transform.InverseTransformDirection(V_BallForce);
float HorizontalRange = ((v.sqrMagnitude) * (Mathf.Sin((2 * (v.normalized.y * Mathf.Rad2Deg))*Mathf.Deg2Rad)) / (2 * -Physics.gravity.y));
//THIS IS THE LATERAL DISTANCE WE NEED TO TRAVEL//
float opposite = (Mathf.Abs(Mathf.Tan(Mathf.Deg2Rad * xdir))) * (HorizontalRange * .5f);
//THIS IS THE TIME IT WILL NEED TO TAKE//
float time = v.magnitude / (HorizontalRange);
//THIS IS THE SPEED THE MAGNUS EFFECT WILL NEED TO PRODUCE//
float linearSpeed =Mathf.Abs((opposite * time))*Mathf.Sign(xdir);
return GO_Camera.transform.TransformDirection((((linearSpeed /( 2 * Mathf.PI * _halfmass * (_BallRadius * .5f))) / 1.429f))*Mathf.Deg2Rad*GO_PGolfBall.transform.up);
}
The result is very inconsistent based on xdir and V_BallForce, sometimes travels further, sometimes barely at all. This has been a pretty sobering adventure in discovering that I'm pretty bad at math.
I think the issue is actually a matter of the calculation for time, though I'm probably wrong. If anyone has any advice for this issue I would be much obliged.
Your answer
Follow this Question
Related Questions
how do I find velocity relative to where my player is looking? 2 Answers
Need Some Help in Mathematics for my Stone Skipping game 0 Answers
In what way do units matter when providing density for Collider2Ds? 0 Answers
Hey I am trying to calculate velocity of a gameObject without using rigidbody 1 Answer