Reputation: 113
Is there any way to rotate kinematic bodies around point different from body's center without using of body.setTransform() method? Because when I use setTransform() physics behavior become strange. I use andengine.
Upvotes: 0
Views: 1370
Reputation: 903
You could use equations for x and y coordinates of a circle. If you use for example code below, every touch on scene would result in angle decrease for 0.1, and this will result in rotation of body around point(xCenter, yCenter) with radius of r.
private float p2m = PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
angle -= 0.1;
Vector2 vector = Vector2Pool.obtain(xCenter/p2m + (r/p2m) * Math.cos(angle), (yCenter/p2m + (r/p2m) * Math.sin(angle));
body.setTransform(vector, angle);
Vector2Pool.recycle(vector);
return false;
}
Upvotes: 0
Reputation: 12527
Does the point it rotates around change? If no, you could offset the body's shapes from the body center. Then when the body rotates, it will rotate around that point.
Another idea would be to use a joint. (*pointed out below)
Upvotes: 1