CharacterVirtualTest.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/Character/CharacterVirtualTest.h>
  6. #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
  7. #include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
  8. #include <Layers.h>
  9. #include <Utils/Log.h>
  10. #include <Renderer/DebugRendererImp.h>
  11. #include <Application/DebugUI.h>
  12. //#define CHARACTER_TRACE_CONTACTS
  13. JPH_IMPLEMENT_RTTI_VIRTUAL(CharacterVirtualTest)
  14. {
  15. JPH_ADD_BASE_CLASS(CharacterVirtualTest, CharacterBaseTest)
  16. }
  17. void CharacterVirtualTest::Initialize()
  18. {
  19. CharacterBaseTest::Initialize();
  20. // Create 'player' character
  21. Ref<CharacterVirtualSettings> settings = new CharacterVirtualSettings();
  22. settings->mMaxSlopeAngle = sMaxSlopeAngle;
  23. settings->mMaxStrength = sMaxStrength;
  24. settings->mShape = mStandingShape;
  25. settings->mBackFaceMode = sBackFaceMode;
  26. settings->mCharacterPadding = sCharacterPadding;
  27. settings->mPenetrationRecoverySpeed = sPenetrationRecoverySpeed;
  28. settings->mPredictiveContactDistance = sPredictiveContactDistance;
  29. settings->mSupportingVolume = Plane(Vec3::sAxisY(), -cCharacterRadiusStanding); // Accept contacts that touch the lower sphere of the capsule
  30. settings->mEnhancedInternalEdgeRemoval = sEnhancedInternalEdgeRemoval;
  31. settings->mInnerBodyShape = sCreateInnerBody? mInnerStandingShape : nullptr;
  32. settings->mInnerBodyLayer = Layers::MOVING;
  33. mCharacter = new CharacterVirtual(settings, RVec3::sZero(), Quat::sIdentity(), 0, mPhysicsSystem);
  34. mCharacter->SetCharacterVsCharacterCollision(&mCharacterVsCharacterCollision);
  35. mCharacterVsCharacterCollision.Add(mCharacter);
  36. // Install contact listener for all characters
  37. for (CharacterVirtual *character : mCharacterVsCharacterCollision.mCharacters)
  38. character->SetListener(this);
  39. // Draw labels on ramp blocks
  40. for (size_t i = 0; i < mRampBlocks.size(); ++i)
  41. SetBodyLabel(mRampBlocks[i], StringFormat("PushesPlayer: %s\nPushable: %s", (i & 1) != 0? "True" : "False", (i & 2) != 0? "True" : "False"));
  42. }
  43. void CharacterVirtualTest::PrePhysicsUpdate(const PreUpdateParams &inParams)
  44. {
  45. CharacterBaseTest::PrePhysicsUpdate(inParams);
  46. // Draw character pre update (the sim is also drawn pre update)
  47. RMat44 com = mCharacter->GetCenterOfMassTransform();
  48. RMat44 world_transform = mCharacter->GetWorldTransform();
  49. #ifdef JPH_DEBUG_RENDERER
  50. mCharacter->GetShape()->Draw(mDebugRenderer, com, Vec3::sOne(), Color::sGreen, false, true);
  51. #endif // JPH_DEBUG_RENDERER
  52. DrawPaddedCharacter(mCharacter->GetShape(), mCharacter->GetCharacterPadding(), com);
  53. // Remember old position
  54. RVec3 old_position = mCharacter->GetPosition();
  55. // Settings for our update function
  56. CharacterVirtual::ExtendedUpdateSettings update_settings;
  57. if (!sEnableStickToFloor)
  58. update_settings.mStickToFloorStepDown = Vec3::sZero();
  59. else
  60. update_settings.mStickToFloorStepDown = -mCharacter->GetUp() * update_settings.mStickToFloorStepDown.Length();
  61. if (!sEnableWalkStairs)
  62. update_settings.mWalkStairsStepUp = Vec3::sZero();
  63. else
  64. update_settings.mWalkStairsStepUp = mCharacter->GetUp() * update_settings.mWalkStairsStepUp.Length();
  65. // Update the character position
  66. mCharacter->ExtendedUpdate(inParams.mDeltaTime,
  67. -mCharacter->GetUp() * mPhysicsSystem->GetGravity().Length(),
  68. update_settings,
  69. mPhysicsSystem->GetDefaultBroadPhaseLayerFilter(Layers::MOVING),
  70. mPhysicsSystem->GetDefaultLayerFilter(Layers::MOVING),
  71. { },
  72. { },
  73. *mTempAllocator);
  74. #ifdef JPH_ENABLE_ASSERTS
  75. // Validate that our contact list is in sync with that of the character
  76. // Note that compound shapes could be non convex so we may detect more contacts than have been reported by the character
  77. // as the character only reports contacts as it is sliding through the world. If 2 sub shapes hit at the same time then
  78. // most likely only one will be reported as it stops the character and prevents the 2nd one from being seen.
  79. uint num_contacts = 0;
  80. for (const CharacterVirtual::Contact &c : mCharacter->GetActiveContacts())
  81. if (c.mHadCollision)
  82. {
  83. JPH_ASSERT(std::find(mActiveContacts.begin(), mActiveContacts.end(), c) != mActiveContacts.end());
  84. num_contacts++;
  85. }
  86. JPH_ASSERT(sShapeType == EType::Compound? num_contacts >= mActiveContacts.size() : num_contacts == mActiveContacts.size());
  87. #endif
  88. // Calculate effective velocity
  89. RVec3 new_position = mCharacter->GetPosition();
  90. Vec3 velocity = Vec3(new_position - old_position) / inParams.mDeltaTime;
  91. // Draw state of character
  92. DrawCharacterState(mCharacter, world_transform, velocity);
  93. }
  94. void CharacterVirtualTest::HandleInput(Vec3Arg inMovementDirection, bool inJump, bool inSwitchStance, float inDeltaTime)
  95. {
  96. bool player_controls_horizontal_velocity = sControlMovementDuringJump || mCharacter->IsSupported();
  97. if (player_controls_horizontal_velocity)
  98. {
  99. // Smooth the player input
  100. mDesiredVelocity = sEnableCharacterInertia? 0.25f * inMovementDirection * sCharacterSpeed + 0.75f * mDesiredVelocity : inMovementDirection * sCharacterSpeed;
  101. // True if the player intended to move
  102. mAllowSliding = !inMovementDirection.IsNearZero();
  103. }
  104. else
  105. {
  106. // While in air we allow sliding
  107. mAllowSliding = true;
  108. }
  109. // Update the character rotation and its up vector to match the up vector set by the user settings
  110. Quat character_up_rotation = Quat::sEulerAngles(Vec3(sUpRotationX, 0, sUpRotationZ));
  111. mCharacter->SetUp(character_up_rotation.RotateAxisY());
  112. mCharacter->SetRotation(character_up_rotation);
  113. // A cheaper way to update the character's ground velocity,
  114. // the platforms that the character is standing on may have changed velocity
  115. mCharacter->UpdateGroundVelocity();
  116. // Determine new basic velocity
  117. Vec3 current_vertical_velocity = mCharacter->GetLinearVelocity().Dot(mCharacter->GetUp()) * mCharacter->GetUp();
  118. Vec3 ground_velocity = mCharacter->GetGroundVelocity();
  119. Vec3 new_velocity;
  120. bool moving_towards_ground = (current_vertical_velocity.GetY() - ground_velocity.GetY()) < 0.1f;
  121. if (mCharacter->GetGroundState() == CharacterVirtual::EGroundState::OnGround // If on ground
  122. && (sEnableCharacterInertia?
  123. moving_towards_ground // Inertia enabled: And not moving away from ground
  124. : !mCharacter->IsSlopeTooSteep(mCharacter->GetGroundNormal()))) // Inertia disabled: And not on a slope that is too steep
  125. {
  126. // Assume velocity of ground when on ground
  127. new_velocity = ground_velocity;
  128. // Jump
  129. if (inJump && moving_towards_ground)
  130. new_velocity += sJumpSpeed * mCharacter->GetUp();
  131. }
  132. else
  133. new_velocity = current_vertical_velocity;
  134. // Gravity
  135. new_velocity += (character_up_rotation * mPhysicsSystem->GetGravity()) * inDeltaTime;
  136. if (player_controls_horizontal_velocity)
  137. {
  138. // Player input
  139. new_velocity += character_up_rotation * mDesiredVelocity;
  140. }
  141. else
  142. {
  143. // Preserve horizontal velocity
  144. Vec3 current_horizontal_velocity = mCharacter->GetLinearVelocity() - current_vertical_velocity;
  145. new_velocity += current_horizontal_velocity;
  146. }
  147. // Update character velocity
  148. mCharacter->SetLinearVelocity(new_velocity);
  149. // Stance switch
  150. if (inSwitchStance)
  151. {
  152. bool is_standing = mCharacter->GetShape() == mStandingShape;
  153. const Shape *shape = is_standing? mCrouchingShape : mStandingShape;
  154. if (mCharacter->SetShape(shape, 1.5f * mPhysicsSystem->GetPhysicsSettings().mPenetrationSlop, mPhysicsSystem->GetDefaultBroadPhaseLayerFilter(Layers::MOVING), mPhysicsSystem->GetDefaultLayerFilter(Layers::MOVING), { }, { }, *mTempAllocator))
  155. {
  156. const Shape *inner_shape = is_standing? mInnerCrouchingShape : mInnerStandingShape;
  157. mCharacter->SetInnerBodyShape(inner_shape);
  158. }
  159. }
  160. }
  161. void CharacterVirtualTest::AddCharacterMovementSettings(DebugUI* inUI, UIElement* inSubMenu)
  162. {
  163. inUI->CreateCheckBox(inSubMenu, "Enable Character Inertia", sEnableCharacterInertia, [](UICheckBox::EState inState) { sEnableCharacterInertia = inState == UICheckBox::STATE_CHECKED; });
  164. inUI->CreateCheckBox(inSubMenu, "Player Can Push Other Virtual Characters", sPlayerCanPushOtherCharacters, [](UICheckBox::EState inState) { sPlayerCanPushOtherCharacters = inState == UICheckBox::STATE_CHECKED; });
  165. inUI->CreateCheckBox(inSubMenu, "Other Virtual Characters Can Push Player", sOtherCharactersCanPushPlayer, [](UICheckBox::EState inState) { sOtherCharactersCanPushPlayer = inState == UICheckBox::STATE_CHECKED; });
  166. }
  167. void CharacterVirtualTest::AddConfigurationSettings(DebugUI *inUI, UIElement *inSubMenu)
  168. {
  169. inUI->CreateComboBox(inSubMenu, "Back Face Mode", { "Ignore", "Collide" }, (int)sBackFaceMode, [=](int inItem) { sBackFaceMode = (EBackFaceMode)inItem; });
  170. inUI->CreateSlider(inSubMenu, "Up Rotation X (degrees)", RadiansToDegrees(sUpRotationX), -90.0f, 90.0f, 1.0f, [](float inValue) { sUpRotationX = DegreesToRadians(inValue); });
  171. inUI->CreateSlider(inSubMenu, "Up Rotation Z (degrees)", RadiansToDegrees(sUpRotationZ), -90.0f, 90.0f, 1.0f, [](float inValue) { sUpRotationZ = DegreesToRadians(inValue); });
  172. inUI->CreateSlider(inSubMenu, "Max Slope Angle (degrees)", RadiansToDegrees(sMaxSlopeAngle), 0.0f, 90.0f, 1.0f, [](float inValue) { sMaxSlopeAngle = DegreesToRadians(inValue); });
  173. inUI->CreateSlider(inSubMenu, "Max Strength (N)", sMaxStrength, 0.0f, 500.0f, 1.0f, [](float inValue) { sMaxStrength = inValue; });
  174. inUI->CreateSlider(inSubMenu, "Character Padding", sCharacterPadding, 0.01f, 0.5f, 0.01f, [](float inValue) { sCharacterPadding = inValue; });
  175. inUI->CreateSlider(inSubMenu, "Penetration Recovery Speed", sPenetrationRecoverySpeed, 0.0f, 1.0f, 0.05f, [](float inValue) { sPenetrationRecoverySpeed = inValue; });
  176. inUI->CreateSlider(inSubMenu, "Predictive Contact Distance", sPredictiveContactDistance, 0.01f, 1.0f, 0.01f, [](float inValue) { sPredictiveContactDistance = inValue; });
  177. inUI->CreateCheckBox(inSubMenu, "Enable Walk Stairs", sEnableWalkStairs, [](UICheckBox::EState inState) { sEnableWalkStairs = inState == UICheckBox::STATE_CHECKED; });
  178. inUI->CreateCheckBox(inSubMenu, "Enable Stick To Floor", sEnableStickToFloor, [](UICheckBox::EState inState) { sEnableStickToFloor = inState == UICheckBox::STATE_CHECKED; });
  179. inUI->CreateCheckBox(inSubMenu, "Enhanced Internal Edge Removal", sEnhancedInternalEdgeRemoval, [](UICheckBox::EState inState) { sEnhancedInternalEdgeRemoval = inState == UICheckBox::STATE_CHECKED; });
  180. inUI->CreateCheckBox(inSubMenu, "Create Inner Body", sCreateInnerBody, [](UICheckBox::EState inState) { sCreateInnerBody = inState == UICheckBox::STATE_CHECKED; });
  181. }
  182. void CharacterVirtualTest::SaveState(StateRecorder &inStream) const
  183. {
  184. CharacterBaseTest::SaveState(inStream);
  185. mCharacter->SaveState(inStream);
  186. bool is_standing = mCharacter->GetShape() == mStandingShape;
  187. inStream.Write(is_standing);
  188. inStream.Write(mAllowSliding);
  189. inStream.Write(mDesiredVelocity);
  190. inStream.Write(mActiveContacts);
  191. }
  192. void CharacterVirtualTest::RestoreState(StateRecorder &inStream)
  193. {
  194. CharacterBaseTest::RestoreState(inStream);
  195. mCharacter->RestoreState(inStream);
  196. bool is_standing = mCharacter->GetShape() == mStandingShape; // Initialize variable for validation mode
  197. inStream.Read(is_standing);
  198. const Shape *shape = is_standing? mStandingShape : mCrouchingShape;
  199. mCharacter->SetShape(shape, FLT_MAX, { }, { }, { }, { }, *mTempAllocator);
  200. const Shape *inner_shape = is_standing? mInnerStandingShape : mInnerCrouchingShape;
  201. mCharacter->SetInnerBodyShape(inner_shape);
  202. inStream.Read(mAllowSliding);
  203. inStream.Read(mDesiredVelocity);
  204. inStream.Read(mActiveContacts);
  205. }
  206. void CharacterVirtualTest::OnAdjustBodyVelocity(const CharacterVirtual *inCharacter, const Body &inBody2, Vec3 &ioLinearVelocity, Vec3 &ioAngularVelocity)
  207. {
  208. // Apply artificial velocity to the character when standing on the conveyor belt
  209. if (inBody2.GetID() == mConveyorBeltBody)
  210. ioLinearVelocity += Vec3(0, 0, 2);
  211. }
  212. void CharacterVirtualTest::OnContactCommon(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
  213. {
  214. // Draw a box around the character when it enters the sensor
  215. if (inBodyID2 == mSensorBody)
  216. {
  217. AABox box = inCharacter->GetShape()->GetWorldSpaceBounds(inCharacter->GetCenterOfMassTransform(), Vec3::sOne());
  218. mDebugRenderer->DrawBox(box, Color::sGreen, DebugRenderer::ECastShadow::Off, DebugRenderer::EDrawMode::Wireframe);
  219. }
  220. // Dynamic boxes on the ramp go through all permutations
  221. Array<BodyID>::const_iterator i = find(mRampBlocks.begin(), mRampBlocks.end(), inBodyID2);
  222. if (i != mRampBlocks.end())
  223. {
  224. size_t index = i - mRampBlocks.begin();
  225. ioSettings.mCanPushCharacter = (index & 1) != 0;
  226. ioSettings.mCanReceiveImpulses = (index & 2) != 0;
  227. }
  228. // If we encounter an object that can push the player, enable sliding
  229. if (inCharacter == mCharacter
  230. && ioSettings.mCanPushCharacter
  231. && mPhysicsSystem->GetBodyInterface().GetMotionType(inBodyID2) != EMotionType::Static)
  232. mAllowSliding = true;
  233. }
  234. void CharacterVirtualTest::OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
  235. {
  236. OnContactCommon(inCharacter, inBodyID2, inSubShapeID2, inContactPosition, inContactNormal, ioSettings);
  237. if (inCharacter == mCharacter)
  238. {
  239. #ifdef CHARACTER_TRACE_CONTACTS
  240. Trace("Contact added with body %08x, sub shape %08x", inBodyID2.GetIndexAndSequenceNumber(), inSubShapeID2.GetValue());
  241. #endif
  242. CharacterVirtual::ContactKey c(inBodyID2, inSubShapeID2);
  243. if (std::find(mActiveContacts.begin(), mActiveContacts.end(), c) != mActiveContacts.end())
  244. FatalError("Got an add contact that should have been a persisted contact");
  245. mActiveContacts.push_back(c);
  246. }
  247. }
  248. void CharacterVirtualTest::OnContactPersisted(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
  249. {
  250. OnContactCommon(inCharacter, inBodyID2, inSubShapeID2, inContactPosition, inContactNormal, ioSettings);
  251. if (inCharacter == mCharacter)
  252. {
  253. #ifdef CHARACTER_TRACE_CONTACTS
  254. Trace("Contact persisted with body %08x, sub shape %08x", inBodyID2.GetIndexAndSequenceNumber(), inSubShapeID2.GetValue());
  255. #endif
  256. if (std::find(mActiveContacts.begin(), mActiveContacts.end(), CharacterVirtual::ContactKey(inBodyID2, inSubShapeID2)) == mActiveContacts.end())
  257. FatalError("Got a persisted contact that should have been an add contact");
  258. }
  259. }
  260. void CharacterVirtualTest::OnContactRemoved(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2)
  261. {
  262. if (inCharacter == mCharacter)
  263. {
  264. #ifdef CHARACTER_TRACE_CONTACTS
  265. Trace("Contact removed with body %08x, sub shape %08x", inBodyID2.GetIndexAndSequenceNumber(), inSubShapeID2.GetValue());
  266. #endif
  267. ContactSet::iterator it = std::find(mActiveContacts.begin(), mActiveContacts.end(), CharacterVirtual::ContactKey(inBodyID2, inSubShapeID2));
  268. if (it == mActiveContacts.end())
  269. FatalError("Got a remove contact that has not been added");
  270. mActiveContacts.erase(it);
  271. }
  272. }
  273. void CharacterVirtualTest::OnCharacterContactCommon(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
  274. {
  275. // Characters can only be pushed in their own update
  276. if (sPlayerCanPushOtherCharacters)
  277. ioSettings.mCanPushCharacter = sOtherCharactersCanPushPlayer || inOtherCharacter == mCharacter;
  278. else if (sOtherCharactersCanPushPlayer)
  279. ioSettings.mCanPushCharacter = inCharacter == mCharacter;
  280. else
  281. ioSettings.mCanPushCharacter = false;
  282. // If the player can be pushed by the other virtual character, we allow sliding
  283. if (inCharacter == mCharacter && ioSettings.mCanPushCharacter)
  284. mAllowSliding = true;
  285. }
  286. void CharacterVirtualTest::OnCharacterContactAdded(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
  287. {
  288. OnCharacterContactCommon(inCharacter, inOtherCharacter, inSubShapeID2, inContactPosition, inContactNormal, ioSettings);
  289. if (inCharacter == mCharacter)
  290. {
  291. #ifdef CHARACTER_TRACE_CONTACTS
  292. Trace("Contact added with character %08x, sub shape %08x", inOtherCharacter->GetID().GetValue(), inSubShapeID2.GetValue());
  293. #endif
  294. CharacterVirtual::ContactKey c(inOtherCharacter->GetID(), inSubShapeID2);
  295. if (std::find(mActiveContacts.begin(), mActiveContacts.end(), c) != mActiveContacts.end())
  296. FatalError("Got an add contact that should have been a persisted contact");
  297. mActiveContacts.push_back(c);
  298. }
  299. }
  300. void CharacterVirtualTest::OnCharacterContactPersisted(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings)
  301. {
  302. OnCharacterContactCommon(inCharacter, inOtherCharacter, inSubShapeID2, inContactPosition, inContactNormal, ioSettings);
  303. if (inCharacter == mCharacter)
  304. {
  305. #ifdef CHARACTER_TRACE_CONTACTS
  306. Trace("Contact persisted with character %08x, sub shape %08x", inOtherCharacter->GetID().GetValue(), inSubShapeID2.GetValue());
  307. #endif
  308. if (std::find(mActiveContacts.begin(), mActiveContacts.end(), CharacterVirtual::ContactKey(inOtherCharacter->GetID(), inSubShapeID2)) == mActiveContacts.end())
  309. FatalError("Got a persisted contact that should have been an add contact");
  310. }
  311. }
  312. void CharacterVirtualTest::OnCharacterContactRemoved(const CharacterVirtual *inCharacter, const CharacterID &inOtherCharacterID, const SubShapeID &inSubShapeID2)
  313. {
  314. if (inCharacter == mCharacter)
  315. {
  316. #ifdef CHARACTER_TRACE_CONTACTS
  317. Trace("Contact removed with character %08x, sub shape %08x", inOtherCharacterID.GetValue(), inSubShapeID2.GetValue());
  318. #endif
  319. ContactSet::iterator it = std::find(mActiveContacts.begin(), mActiveContacts.end(), CharacterVirtual::ContactKey(inOtherCharacterID, inSubShapeID2));
  320. if (it == mActiveContacts.end())
  321. FatalError("Got a remove contact that has not been added");
  322. mActiveContacts.erase(it);
  323. }
  324. }
  325. void CharacterVirtualTest::OnContactSolve(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, Vec3Arg inContactVelocity, const PhysicsMaterial *inContactMaterial, Vec3Arg inCharacterVelocity, Vec3 &ioNewCharacterVelocity)
  326. {
  327. // Ignore callbacks for other characters than the player
  328. if (inCharacter != mCharacter)
  329. return;
  330. // Don't allow the player to slide down static not-too-steep surfaces when not actively moving and when not on a moving platform
  331. if (!mAllowSliding && inContactVelocity.IsNearZero() && !inCharacter->IsSlopeTooSteep(inContactNormal))
  332. ioNewCharacterVelocity = Vec3::sZero();
  333. }