로프를 사용할 때 원과 조인트를 사용하여 Box2d에서 만든 게임을 개발 중입니다. 밧줄은 낮은 힘으로 드래그 할 때 예상대로 작동하고, 다른 경우에는 (힘이 더 클 때) 미친 듯이 늘어납니다. 나는 그것을 고정하고보다 안정된 로프를 만드는 방법을 모릅니다. 나는 여러 종류의 관절 (RopeJoint, RevoluteJoint, DistanceJoint 등)을 시도했지만 쓸모가 없습니다.미친 듯이 늘어나는 LibGDX Box2D 로프
public class RopeItem {
public Body body;
private com.badlogic.gdx.graphics.g2d.Sprite bodySprite;
float width, length;
public CircleShape shape;
public RopeItem(World world, float width, float height, BodyType bodyType, Vector2 position) {
super();
//init body
BodyDef bodyDef = new BodyDef();
bodyDef.type = bodyType;
bodyDef.position.set(position);
this.body = world.createBody(bodyDef);
//init shape
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.density = 0.1f;
fixtureDef.friction = 0.4f;
fixtureDef.restitution = 0.2f;
shape = new CircleShape();
shape.setRadius(width/2);
fixtureDef.shape = shape;
fixtureDef.filter.categoryBits = 0x0001;
fixtureDef.filter.maskBits = 0x0002;
this.body.createFixture(fixtureDef);
shape.dispose();
//create a body sprite
bodySprite = new com.badlogic.gdx.graphics.g2d.Sprite(new TextureRegion(new Texture("data/rope_circle.png")));
bodySprite.setSize(width, height);
bodySprite.setOrigin(width/2, height/2);
body.setUserData(bodySprite);
}
}
public void createRope(int length) {
RevoluteJoint[] joints = new RevoluteJoint[length - 1];
RopeJoint[] ropeJoints = new RopeJoint[length - 1];
float width = 0.23f, height = 0.23f;
for(int i=0; i<length; i++) {
ropeSegmenets.add(new RopeItem(world, width, height, BodyType.DynamicBody, new Vector2(0.3f, 0)));
}
RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.localAnchorA.x = -height/2;
jointDef.localAnchorB.x = height/2;
RopeJointDef ropeJointDef = new RopeJointDef();
ropeJointDef.localAnchorA.set(0, -height/2);
ropeJointDef.localAnchorB.set(0, height/2);
ropeJointDef.maxLength = length;
for(int i = 0; i < length-1; i++) {
jointDef.bodyA = ropeSegmenets.get(i).body;
jointDef.bodyB = ropeSegmenets.get(i + 1).body;
joints[i] = (RevoluteJoint) world.createJoint(jointDef);
ropeJointDef.bodyA = ropeSegmenets.get(i).body;
ropeJointDef.bodyB = ropeSegmenets.get(i+1).body;
ropeJoints[i] = (RopeJoint) world.createJoint(ropeJointDef);
}
}
스크린 샷 : 일반
: 뻗어
:
다음은 내 코드입니다3210이 문제를 해결하는 방법을 알고 있다면 도와주세요.
감사합니다. Charlie!
감사합니다 많이! 내 로프가 지금은 더 안정적입니다. – user1929598