nfurtwangler wrote:
Do you have a scale factor applied between your physics and rendering layer? You usually want one.
Otherwise, one pixel is equivalent to one meter, so going off the screen is like traveling over a kilometer! There is a max linear velocity which you can modify but you really shouldn't need to in most cases since it is quite larger (on the order of
300mph).
Ok got it, I guess I'll explain what i did since it took me a week to realize it.
Box2D is tuned for meterskilogramsseconds (MKS). Your moving objects should be between 0.1  10 meters.
So what i did is since i have a ball with Dimensions of 25x25 pixels, i decided to just use a scaling factor of 0.01. So that means in the physics world the radius would be .125f, diameter is .25f. So i did
var circleShape = new CircleShape();
circleShape._radius =0.125f;
and for the border, they would have to be scaled too.
var groundDef = new BodyDef();
groundDef.type = BodyType.Static;
var shape = new PolygonShape();
var topBody = world.CreateBody(groundDef);
shape.SetAsEdge(new Vector2(0, 0.48f), new Vector2(8f,0.48f));
topBody.CreateFixture(shape, 0.0f);
so now, all I did is in my draw method is, notice i divided by the scale factor.
spriteBatch.Draw(ballzTexutre, new Vector2(ballBody.Position.X/0.01f,ballBody.Position.Y/0.01f),null, Color.White,ballBody.Rotation,new Vector2(12.5f,12.5f),1,SpriteEffects.None,0);
