Game Development Reference
In-Depth Information
} else if(!leanFree && leanValue > 0f){
leanValue -= 0.5f * tpf;
}
[mirror for right]
if(leanValue < 0.005f && leanValue > -0.005f){
leanValue = 0f;
}
if(leanValue != 0f){
lean(leanValue);
} else {
leaningBone.setUserControl(false);
}
}
6. In the lean method, which applies the leaning to the bone, the first thing we do
is clamp the value to be inside the allowed threshold. Next, we call setUser-
Control on the bone to let it know that it shouldn't apply animations before cre-
ating a new Quaternion class based on the original rotation, as shown in the
following code:
private void lean(float value){
FastMath.clamp(value, -maxLean, maxLean);
leaningBone.setUserControl(true);
Quaternion newQuat = boneRotation.add(new
Quaternion().fromAngles(-FastMath.QUARTER_PI * 0.35f,
0, -value));
newQuat.normalizeLocal();
leaningBone.setLocalRotation(newQuat);
}
Search WWH ::




Custom Search