Hi
i'm trying to create a nice looking animation for a flying rocket(my arrow is an weldjoint between an circle and a box)
i tried to auto-align it by making the explisive head heavy and the rest lighter, which looks quite good, but when i hit something it starts spinning, and actually i just want the tail to align to the direction of movement.
this is my current code:
i'm trying to create a nice looking animation for a flying rocket(my arrow is an weldjoint between an circle and a box)
i tried to auto-align it by making the explisive head heavy and the rest lighter, which looks quite good, but when i hit something it starts spinning, and actually i just want the tail to align to the direction of movement.
this is my current code:
Code: Select all
Player p = rocket.getOwner();
Vec2 norm = p.getCrosshair().getTarget().clone();
Vec2 rocketStartPos = p.getCrosshair().getPosition();
// relevant stuff starts here
CircleShapeBuilder csb = new CircleShapeBuilder(getWorld());
csb.type(BodyType.DYNAMIC);
csb.position(rocketStartPos.add(norm.mul(0.125f)));
csb.radius(rocket.getRadius());
csb.density(0.5f);
csb.friction(0.003f);
csb.userData(rocket); // append the user data for later
// processing
Body explosives = csb.build();
BoxBuilder bb = new BoxBuilder(getWorld());
bb.type(BodyType.DYNAMIC);
Vec2 createPos = rocket.getOwner().getCrosshair().getPosition().sub(norm.mul(rocket.getRadius()));
bb.position(createPos);
bb.halfHeight(rocket.getRadius());
bb.halfWidth(rocket.getRadius() * 1.5f);
bb.density(0.05f);
bb.friction(0.003f);
bb.userData(rocket); // append the user data for later
float radians = (float) Math.atan2(norm.y, norm.x);
bb.angle(radians);
Body rockedBody = bb.build();
WeldJointDef jointDef = new WeldJointDef();
jointDef.initialize(explosives, rockedBody, explosives.getWorldCenter());
world.createJoint(jointDef);
rocket.setBody(explosives); // set the body to my data-class