prevent twist limits being created with equal lower and upper limits
Signed-off-by: greerdv <greerdv@amazon.com>
This commit is contained in:
@@ -224,8 +224,22 @@ namespace PhysX {
|
||||
physx::PxJointLimitCone limitCone(swingLimitY, swingLimitZ);
|
||||
joint->setSwingLimit(limitCone);
|
||||
|
||||
const 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 twistLower = AZ::DegToRad(AZStd::GetMin(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);
|
||||
joint->setTwistLimit(twistLimitPair);
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@ namespace PhysX
|
||||
{
|
||||
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.
|
||||
static const float MinSwingLimitDegrees = 1.0f;
|
||||
// Minimum range between lower and upper twist limits.
|
||||
static const float MinTwistLimitRangeDegrees = 1.0f;
|
||||
} // namespace JointConstants
|
||||
|
||||
namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user