Hello
I can for some reason not get a circle to move using box2D, but if I make it into a Polygon it seems to work without problems.
The code I use when creating the circle:
If i now change it to the following, it will move, but it's not a circle, it's a polygon:
Disregard the name of the PolygonDef.
This is the output in the debug:
And as you can see, it doesn't want to move.
For some reason, the position is also way off, as I normally use around 5 meters x and y for my position, but if I use that on my CircleDef, it ends up in my wall?
Could anyone maybe explain what is going on? Or what I am doing wrong?
I can for some reason not get a circle to move using box2D, but if I make it into a Polygon it seems to work without problems.
The code I use when creating the circle:
Code:
CircleDef circleDef = new CircleDef();
circleDef.radius = 10;
circleDef.friction = 0.3f;
circleDef.restitution = 0.2f;
circleDef.density = 1f;
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(30, 5);
bodyDef.angle = (float)(30 * Math.PI / 180);
ball = world.createBody(bodyDef);
ball.createShape(circleDef);
ball.setMassFromShapes();
circleDef.radius = 10;
circleDef.friction = 0.3f;
circleDef.restitution = 0.2f;
circleDef.density = 1f;
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(30, 5);
bodyDef.angle = (float)(30 * Math.PI / 180);
ball = world.createBody(bodyDef);
ball.createShape(circleDef);
ball.setMassFromShapes();
If i now change it to the following, it will move, but it's not a circle, it's a polygon:
Disregard the name of the PolygonDef.
Code:
PolygonDef circleDef = new PolygonDef();
circleDef.setAsBox(1, 1);
circleDef.friction = 0.3f;
circleDef.restitution = 0.2f;
circleDef.density = 1f;
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(30, 5);
bodyDef.angle = (float)(30 * Math.PI / 180);
ball = world.createBody(bodyDef);
ball.createShape(circleDef);
ball.setMassFromShapes();
circleDef.setAsBox(1, 1);
circleDef.friction = 0.3f;
circleDef.restitution = 0.2f;
circleDef.density = 1f;
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(30, 5);
bodyDef.angle = (float)(30 * Math.PI / 180);
ball = world.createBody(bodyDef);
ball.createShape(circleDef);
ball.setMassFromShapes();
This is the output in the debug:
Code:
06-24 00:31:42.010: DEBUG/GraphicTest Debug(15459): Circle: (30.0,5.0027223)
06-24 00:31:42.025: DEBUG/GraphicTest Debug(15459): Circle: (30.0,5.0027223)
06-24 00:31:42.041: DEBUG/GraphicTest Debug(15459): Circle: (30.0,5.0027223)
06-24 00:31:42.025: DEBUG/GraphicTest Debug(15459): Circle: (30.0,5.0027223)
06-24 00:31:42.041: DEBUG/GraphicTest Debug(15459): Circle: (30.0,5.0027223)
And as you can see, it doesn't want to move.
For some reason, the position is also way off, as I normally use around 5 meters x and y for my position, but if I use that on my CircleDef, it ends up in my wall?
Could anyone maybe explain what is going on? Or what I am doing wrong?