Browse Source

Fixed bug that caused character to slide from static geometry

Jorrit Rouwe 3 years ago
parent
commit
609de13ee6

+ 9 - 0
Jolt/Physics/Body/BodyInterface.cpp

@@ -748,6 +748,15 @@ void BodyInterface::SetMotionType(const BodyID &inBodyID, EMotionType inMotionTy
 	}
 }
 
+EMotionType BodyInterface::GetMotionType(const BodyID &inBodyID) const
+{
+	BodyLockRead lock(*mBodyLockInterface, inBodyID);
+	if (lock.Succeeded())
+		return lock.GetBody().GetMotionType();
+	else
+		return EMotionType::Static;
+}
+
 Mat44 BodyInterface::GetInverseInertia(const BodyID &inBodyID) const
 {
 	BodyLockRead lock(*mBodyLockInterface, inBodyID);

+ 4 - 1
Jolt/Physics/Body/BodyInterface.h

@@ -159,8 +159,11 @@ public:
 	void						AddAngularImpulse(const BodyID &inBodyID, Vec3Arg inAngularImpulse);
 	///@}
 
-	/// Update the body motion type
+	///@name Body motion type
+	///@{
 	void						SetMotionType(const BodyID &inBodyID, EMotionType inMotionType, EActivation inActivationMode);
+	EMotionType					GetMotionType(const BodyID &inBodyID) const;
+	///@}
 
 	/// Get inverse inertia tensor in world space
 	Mat44						GetInverseInertia(const BodyID &inBodyID) const;

+ 1 - 1
Samples/Tests/Character/CharacterVirtualTest.cpp

@@ -221,7 +221,7 @@ void CharacterVirtualTest::OnContactAdded(const CharacterVirtual *inCharacter, c
 	}
 
 	// If we encounter an object that can push us, enable sliding
-	if (ioSettings.mCanPushCharacter)
+	if (ioSettings.mCanPushCharacter && mPhysicsSystem->GetBodyInterface().GetMotionType(inBodyID2) != EMotionType::Static)
 		mAllowSliding = true;
 }