As far as I understand it, this should cause the body to move. I have an update method in the class but I'm not sure what else to add. I am using box2d as part of libgdx. Everywhere I've looked it just says to set the linear velocity, but it isn't working.
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(new Vector2(pos.x, pos.y));
bodyDef.type = BodyDef.BodyType.KinematicBody;
bodyDef.linearDamping = 0.0f;
bodyDef.angularDamping = 0.0f;
unitBoxBody = world.createBody(bodyDef);
PolygonShape player = new PolygonShape();
player.setAsBox(unit * xSize, unit * ySize);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = player;
fixtureDef.density = 0.0f;
fixtureDef.friction = 0.0f;
fixtureDef.restitution = 0.0f;
fixture = unitBoxBody.createFixture(fixtureDef);
player.dispose();
unitBoxBody.setLinearVelocity(10, 0);
I have used numerous large and small values for the velocity with no change.
fixtureDef.density = 0.0f
, this seems kind of odd since if you apply force to a massless object, it would have infinite acceleration. Not too sure how that's handled by Box2D. Also are you callingworld.step()
in your main loop? – XiaoChuan Yurender(float delta)
method or your principal loop method – Alex Sifuentes