- Home /
The question is answered, right answer was accepted
Objects displacement after applying force doesn't match calculations
Hello, I'm trying to test just a simple setting using AddForce and I have difference between results from unity and results from math equation, Couldn't find out what's wrong any tips would be appreciated... m = 1; gravity and drag are turned off. Starting position is (0; 0) Objects final position becomes (202; 0). However with my calculations I should get (200; 0). Since F=ma, (F = 100, m = 1) => a = 100. S = 1/2 a t2 (t = 0.02 * 100, since deltatime for fixed update is 0.02 and I add force 100 times) so I get S = 200, But unity says 202, I get similar results In case I use impulse force mode. What do I miss?
int count = 0;
float x = 100;
float y = 0;
Vector2 force;
Rigidbody2D rb2d;
void Start ()
{
rb2d = GetComponent<Rigidbody2D>();
force = new Vector2(x, y);
}
void FixedUpdate()
{
if (count < 100)
{
rb2d.AddForce(force);
}
else
{
rb2d.velocity = Vector2.zero;
rb2d.angularVelocity = 0;
}
count++;
}
If I set x = 10 final position is (2,2 ; 0). If I set x = 1, than - (0.04 ; 0). Neither of these match my calculations.
Answer by pako · Oct 30, 2017 at 08:33 PM
The Physics simulation is an approximation. In your example you are using the 2D Physics engine, but there's a very good explanation of the approximations in the 3D Engine PhysX manual . Check out the Physics vs. PhysX section: