How to calculate position of RigidBody after applying force?

Hello

A bit of background first. I have this project of a game that teaches physics ( or at least is helping to).

In first experiment, player needs to move cannon to specific location by recoil (shooting cannonball).
Player can choose mass of cannonball and the muzzle velocity.

And here is the question: How to calculate the final position that cannon will be at when force is applied? Cannon only moves back horizontally.
Because i want player to actually be able to calculate what cannonball to use and what muzzle velocity should be, without guessing.

The whole experiment works btw.

Here how it looks in game:

Cannon:
8479727--1127306--upload_2022-9-30_15-9-21.png

And here is relevant code:

private void StartTest()
    {
        if(cannonballItem == null) { return; }

        ballRB.mass = cannonballItem.Mass;

        velocityBall = float.Parse(velocityBallText.text);

        force = ballRB.mass * velocityBall;

        ballForce = new Vector3(0f, 0f, force);
        cannonForce = new Vector3(0f, 0f, -force);

        ball.transform.localPosition = visiblePosOfBall;
        ballRB.useGravity = true;
        ballCollider.enabled = true;

        ballRB.AddForce(ballForce, ForceMode.Impulse);
        cannonRB.AddForce(cannonForce, ForceMode.Impulse);

        testEnded = true;
        cannonUseItemHandler.CanRetriveItems = false;
    }

This is tricky because it depends on what you’re trying to teach. From my perspective, there are two effects:

  1. Conservation of impulse when the cannon fires
  2. Dissipation of kinetic energy when cannon moves (drag)

So the first one is obvious: the bigger the mass of the cannonball, the greater the velocity of the cannon after firing
The second one is trickier and depends on the friction or damping model of the cannon. Assuming linear drag, the cannon will never come to rest but just keep going slower and slower. Assuming constant drag (probably what you want) you can calculate the position over time as a polynomial.

I would recommend instead of using PhysX, go for the algebraic description of the problem. You’ll know exactly what’s happening, it’s easier to debug, it’s absolutely deterministic on all machines and no guesswork about the inner workings of a physics engine.