0
\$\begingroup\$

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.

Box2d-js

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.

Unity3d

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.

\$\endgroup\$
2
  • \$\begingroup\$ Do you know the standard kinematics equations for motion under a constant acceleration (your friction force) as described in my answer here? gamedev.stackexchange.com/questions/54732/… \$\endgroup\$ Jun 3, 2016 at 3:27
  • \$\begingroup\$ I dont want to do kinematics, I need a full simulation of physics, but thanks. \$\endgroup\$
    – Undume
    Jun 3, 2016 at 8:09

1 Answer 1

0
\$\begingroup\$

Your Box2D method sounds great, but that kind of stuff only works when you understand exactly how the engine works.

You could You start with a strong push force, and then you use an opposite force, which you increase while you get closer to the desired place.

But if you want to move an object to a specific position, I think that the best way is to do it manually. On each frame, you move the object a small step, and you reduce that step over time to simulate deceleration.

\$\endgroup\$
1
  • \$\begingroup\$ I need to make this clean. I will make 4-5 coins being pushed at the same time and probably colliding between them. In any of your suggestions the physics will seem wierd. \$\endgroup\$
    – Undume
    Jun 3, 2016 at 7:58

Not the answer you're looking for? Browse other questions tagged .