Closed grimaldini closed 4 years ago
Because you are using the latest version of Box2D. I'm working on upgrade Box2DSharp to the latest commit of Box2D, it should be fine when I finished.
That's strange, because I ported the recent changes of Box2D to my fork of your repo. Are you sure that your repo is ported up to Box2D's a174dbac1bc32e05e790cd867d9e30fb37681d47 commit?
Unless there is some unfound bugs. For floating-poing number, C++ and C# calculations may have errors that add up to inconsistent results.
Check dev
branch, it is the same now.
Are you sure? I just downloaded dev
and tested it and got the same result as before
I haven't tested it in the test-bed though (it's not running well for mac), so I wonder if maybe something got changed there since back then. Did you notice anything while porting the test-bed?
Try this, the only different is that groundBodyDef.BodyType
is BodyType.DynamicBody
, not BodyType.StaticBody
World.Gravity = new Vector2(0, -10);
var chainShape = new ChainShape();
chainShape.CreateLoop(
new[]
{
new Vector2(-5, 0),
new Vector2(5, 0),
new Vector2(5, 5),
new Vector2(4, 1),
new Vector2(-4, 1),
new Vector2(-5, 5)
});
var groundFixtureDef = new FixtureDef
{
Density = 0,
Shape = chainShape
};
var groundBodyDef = new BodyDef
{
BodyType = BodyType.DynamicBody
};
var groundBody = World.CreateBody(groundBodyDef);
groundBody.CreateFixture(groundFixtureDef);
var ballShape = new CircleShape {Radius = 1};
var ballFixtureDef = new FixtureDef
{
Density = 1,
Restitution = 0.75f,
Shape = ballShape
};
var ballBodyDef = new BodyDef
{
BodyType = BodyType.DynamicBody,
Position = new Vector2(0, 10)
};
var ball = World.CreateBody(ballBodyDef);
ball.CreateFixture(ballFixtureDef);
ball.ApplyForceToCenter(new Vector2(-1000, -400), true);
Oh you are right, good catch! I don't know how I didn't notice that I wrote dynamic instead of static in my c++ example above. However, this seems to be a bug with Box2D right? Because I printed out the velocity that the ball had on the last bounce when the ground is static and then the velocity right before it touches the other side and the velocity was greater at the end than at the beginning which means the ball wasn't slowing down but rather picking up speed. Maybe I should file a bug on Box2D...
Since Box2D commit 60d36c498bc86afa0cd140d7b9fc37d5df76a39a
- 2020-03-09 12:13:35
it changes the behavior about zero density dynamic body, I think that's the key.
If you have installed Unity, you can test this scene in UnityTest
, I got the same result
Thanks for helping debug this!
Hello,
I have this set-up running using Box2DSharp:
and this one, an identical one running Box2D:
I also made sure that both b2Settings were set the same. As you might notice the original Box2D seems to be quicker at damping the force of the ball, my guess is that this might have something to do with the friction calculation or maybe a rounding issue. In this example, the original Box2D ball stops right away, while on Box2DSharp, the ball keeps on going even after colliding against the ball and then until it collides the other wall, but it takes a really long time for it to move, but makes it there. So the results are very different. Any ideas of what could be causing this?