In a 3D world I simulate that a coin is being pushed over a plane (applying a force in his rigidbody where y-axis = 0) using a top-down view.
Some time ago but using Box2D, I was able to calculate the amount of force required to stop the coin in a desired position with just one push.
var fps=60; var groundFriction = 0.01; var force= new Box2D.Common.Math.b2Vec2(distance.x * coin.box2dBody.GetMass() * fps * (groundFriction * fps), distance.y * coin.box2dBody.GetMass()* fps *(groundFriction * fps)); coin.box2dBody.ApplyForce( force, coin.box2dBody.GetWorldCenter(), true );
In order to simulate the friction, during the update, I substracted the groundFriction(0.01) to the linearvelocity of the objects in movement in every frame.
Now using Unity with a more complex physics engine I cant replicate the same.
Vector3 posFinal = transform.position + direction * distFinal; Vector3 distanceVecFinal = posFinal - transform.position; float fps= 1/Time.fixedDeltaTime //50 fps Vector3 force = new Vector3(distanceVecFinal.x * myBody.mass * fps, 0, distanceVecFinal.z * myBody.mass * fps); myBody.AddForce(force);
I think that in the final formula I should add the friction of the objects, but I am not sure how to do it. Maybe this is not the only thing that I should change.
I need help pls!
tl&dr Calculate the required force for making move an object to a desired position in a plane with just one push.