I’m trying to make a RevoluteJoint with a body (with CircleShape) and another body (with PolygonShape), but it don’t change the rotation and I don’t know why not…
I have a class with the joint (the bodies and all inside it) for use it more easily:
[spoiler]
package unclain.gametest1.objects;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.RevoluteJoint;
import com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef;
public class BasicJointPlatform {
public World world;
public RevoluteJointDef rjd;
public BodyDef bdbodyA;
public Body bbodyA;
public FixtureDef fdbodyA;
public Fixture fbodyA;
public BodyDef bdbodyB;
public Body bbodyB;
public FixtureDef fdbodyB;
public Fixture fbodyB;
public float x;
public float y;
public BasicJointPlatform(World world, float x, float y, float rectWidth, float rectHeight){
this.world = world;
this.x = x;
this.y = y;
bodyA(world);
bodyB(world, x, y, rectWidth, rectHeight);
rjd = new RevoluteJointDef();
rjd.bodyA = bbodyA;
rjd.bodyB = bbodyB;
rjd.maxMotorTorque = 10000f;
rjd.enableMotor = true;
RevoluteJoint rj = (RevoluteJoint) world.createJoint(rjd);
rj.setMotorSpeed(1f);
}
public void bodyA(World world){
bdbodyA = new BodyDef();
bdbodyA.position.set(new Vector2(x, y + 15));
bdbodyA.type = BodyType.StaticBody;
bbodyA = world.createBody(bdbodyA);
CircleShape cs = new CircleShape();
cs.setRadius(4f);
fdbodyA = new FixtureDef();
fdbodyA.density = 1f;
fdbodyA.shape = cs;
fbodyA = bbodyA.createFixture(fdbodyA);
cs.dispose();
}
public void bodyB(World world, float x, float y, float rectWidth, float rectHeight){
bdbodyB = new BodyDef();
bdbodyB.position.set(new Vector2(x, y));
bdbodyB.type = BodyType.StaticBody;
bbodyB = world.createBody(bdbodyB);
PolygonShape ps = new PolygonShape();
ps.setAsBox(rectWidth, rectHeight);
fdbodyB = new FixtureDef();
fdbodyB.density = 1f;
fdbodyB.shape = ps;
fbodyB = bbodyB.createFixture(fdbodyB);
ps.dispose();
}
}
[/spoiler]
and another class with all the joints:
[spoiler]
package unclain.gametest1;
import unclain.gametest1.objects.BasicJointPlatform;
import com.badlogic.gdx.physics.box2d.World;
public class Platforms {
public World world;
public BasicJointPlatform platform1, platform2, platform3, platform4;
public Platforms(World world){
this.world = world;
}
public void createPlatforms(){
platform1 = new BasicJointPlatform(world, 50, -30, 8f, 30f);
platform2 = new BasicJointPlatform(world, 150, -30, 8f, 30f);
platform3 = new BasicJointPlatform(world, 250, -30, 8f, 30f);
platform4 = new BasicJointPlatform(world, 350, -30, 8f, 30f);
}
}
[/spoiler]
But when I run the game, it don’t do anything…
Why my revolutejoint don’t work?
[spoiler]
The joint don’t work when I collide with it…
[/spoiler]