Skip to content

Instantly share code, notes, and snippets.

@nanonull
Created January 7, 2016 18:42
Show Gist options
  • Save nanonull/0e8aa16159fa8fc03431 to your computer and use it in GitHub Desktop.
Save nanonull/0e8aa16159fa8fc03431 to your computer and use it in GitHub Desktop.
protected void process(Entity e) {
// TODO if baseBody was destroyed then disable rotation
StationaryGunMotorComponent gunComponent = components.get(e);
Box2dBodyComponent bodyComponent = Box2dBodySystem.components.get(e);
float desiredWorldAngle = gunComponent.getDesiredWorldAngleRads();
float currWorldAngle = MathUtilsExt.absRadians(bodyComponent.body.getAngle());
float angleDelta = MathUtilsExt.diffAbsoluteRadians(currWorldAngle, desiredWorldAngle);
if (MathUtilsExt.areDecimalsEqual(angleDelta, 0)) {
return;
}
// act motor
Box2dMotorJointActionComp motorJointActionComp = Box2dMotorJointActionSystem.components.create(e);
motorJointActionComp.force = (angleDelta / Math.abs(angleDelta)) * FORCE_DELTA;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment