prevent twist limits being created with equal lower and upper limits

Signed-off-by: greerdv <greerdv@amazon.com>
monroegm-disable-blank-issue-2
greerdv 4 years ago
parent 87c7023e3c
commit d945a031c1

@ -224,8 +224,22 @@ namespace PhysX {
physx::PxJointLimitCone limitCone(swingLimitY, swingLimitZ); physx::PxJointLimitCone limitCone(swingLimitY, swingLimitZ);
joint->setSwingLimit(limitCone); joint->setSwingLimit(limitCone);
const float twistLower = AZ::DegToRad(AZStd::GetMin(configuration.m_twistLimitLower, configuration.m_twistLimitUpper)); float twistLower = AZ::DegToRad(AZStd::GetMin(configuration.m_twistLimitLower, configuration.m_twistLimitUpper));
const float twistUpper = AZ::DegToRad(AZStd::GetMax(configuration.m_twistLimitLower, configuration.m_twistLimitUpper)); float twistUpper = AZ::DegToRad(AZStd::GetMax(configuration.m_twistLimitLower, configuration.m_twistLimitUpper));
// make sure there is at least a small difference between the lower and upper limits to avoid problems in PhysX
const float minSwingLimitRangeRadians = AZ::DegToRad(JointConstants::MinTwistLimitRangeDegrees);
if (const float twistLimitRange = twistUpper - twistLower;
twistLimitRange < minSwingLimitRangeRadians)
{
if (twistUpper > 0.0f)
{
twistLower -= (minSwingLimitRangeRadians - twistLimitRange);
}
else
{
twistUpper += (minSwingLimitRangeRadians - twistLimitRange);
}
}
physx::PxJointAngularLimitPair twistLimitPair(twistLower, twistUpper); physx::PxJointAngularLimitPair twistLimitPair(twistLower, twistUpper);
joint->setTwistLimit(twistLimitPair); joint->setTwistLimit(twistLimitPair);

@ -18,9 +18,11 @@ namespace PhysX
{ {
namespace JointConstants namespace JointConstants
{ {
// Setting swing limits to very small values can cause extreme stability problems, so clamp above a small // Setting joint limits to very small values can cause extreme stability problems, so clamp above a small
// threshold. // threshold.
static const float MinSwingLimitDegrees = 1.0f; static const float MinSwingLimitDegrees = 1.0f;
// Minimum range between lower and upper twist limits.
static const float MinTwistLimitRangeDegrees = 1.0f;
} // namespace JointConstants } // namespace JointConstants
namespace Utils namespace Utils

Loading…
Cancel
Save