Search Unity

Need formula to calculate Max Distance and Required Force

Discussion in 'Physics' started by Munkey, Oct 19, 2021.

  1. Munkey

    Munkey

    Joined:
    Oct 26, 2013
    Posts:
    23
    Hi,

    I'm working on a Top Down 2D game which uses physics to propel and bounce objects around the scene. However, I admit I'm no math wiz, so I was hoping someone might be able to help me out with a few formulas.

    1 - Get the Distance an object can travel given a specified amount of Force.

    2 - Get the Force required to travel a certain Distance.

    Here are (what I assume to be) the primary components/properties to consider:

    Angular friction/drag/rotation is always ignored.
    Rigidbody's Linear Drag is always 0. Instead, we use the FrictionJoint2D.

    The Rigidbody's Mass varies but it is usually 0.25, 1, or 2
    FrictionJoint2D's Max Force varies, but is usually 7, 25, or 50

    rigidbody.AddForce() is always used to get the objects moving, with the ForceMode2D.Impulse type.

    Below is an example of the gameplay. These formulas will assist the AI in making decent shots of it's own! pit toss.gif

    Would love to talk more with a Physics wiz! Thank you!
     
  2. Munkey

    Munkey

    Joined:
    Oct 26, 2013
    Posts:
    23
    Figured it out and posting the results incase anyone else ever needs this kind of thing
    Code (CSharp):
    1. public void AddForce()
    2.     {
    3.         _rb.AddForce(Force * Direction, ForceMode2D.Impulse);
    4.        
    5.         var friction = _frictionJoint.maxForce;
    6.         var predictionDistance = Math.Pow(Force, 2) / (2 * friction * _rb.mass);
    7.        
    8.         var requiredForce = Math.Sqrt(predictionDistance * 2 * friction * _rb.mass);
    9.        
    10.         Debug.Log($"Force: {Force}, Friction: {friction}, Distance Predicted: {predictionDistance} ");
    11.         Debug.Log($"Required Force: {requiredForce}");
    12.     }
     
    beatsbytex and pilehead like this.