Game Development Reference
In-Depth Information
6. We get the current rotation of
bodyA
to see how much it pivots. We then convert
the rotation to angles and store them as follows:
float[] anglesA = new float[3];
bodyA.getPhysicsRotation().toAngles(anglesA);
7. We then store
angles[0]
in a float variable called
x
.
8. If
x
is more than 0.01f or less than -0.01, we should start
motorX
and rotate it to
compensate for the pivot, as follows:
motorX.setEnableMotor(true);
motorX.setTargetVelocity(x*1.1f);
motorX.setMaxMotorForce(13.5f);
9. Otherwise, we turn off the motor as follows:
motorX.setTargetVelocity(0);
motorX.setMaxMotorForce(0);