Increasing Velocity/Acceleration

Jun 24, 2010 at 5:20 AM

I am having a problem, and i have tried all the possible combinations. I am trying to get my ball to just basically fly off the screen as fast as possible. The only problem is no matter what values i set it justmoves at the same rate. I tried doing

 

 ballBody.SetLinearVelocity(new Vector2(1000000f, 0));

 ballBody.SetLinearVelocity(new Vector2(10f, 0));

And every number in between, and the ball still moves at the same speed. What Exactly am i doing wrong. Also the code for the body is below . All i want is for the ball to go really fast, almost like a Pinball machine.

 

var bodyDef = new BodyDef();
            bodyDef.position = new Vector2(400, 200);
            
            bodyDef.type = BodyType.Dynamic;
            bodyDef.fixedRotation = true;
           

            ballBody = world.CreateBody(bodyDef);

            var circleShape = new CircleShape();
            circleShape._radius = 12.5f;

            var fixtureDef = new FixtureDef();
            fixtureDef.restitution = 1.4f;
            fixtureDef.shape = circleShape;
            fixtureDef.friction = 0;
          
           
            ballBody.CreateFixture(fixtureDef);

Coordinator
Jun 25, 2010 at 2:07 AM

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).

Jun 25, 2010 at 3:16 AM
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 meters-kilograms-seconds (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);