Don't set the player to previous position when uncrouching.
This commit is contained in:
@@ -66,7 +66,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool& jitterGuard = (bool&)entity["Collidable"]["JitterGuard"];
|
||||
// Collide against octree items
|
||||
m_OctreeResult.clear();
|
||||
m_Octree->ObjectsInSameRegion(*boundingBox, m_OctreeResult);
|
||||
@@ -93,7 +93,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
||||
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
|
||||
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
|
||||
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
|
||||
(glm::vec3&)cTransform["Position"] += jitterGuard && notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
|
||||
boxA = *Collision::EntityAbsoluteAABB(entity);
|
||||
cPhysics["Velocity"] = inOutVelocity;
|
||||
if (isOnGround) {
|
||||
@@ -118,6 +118,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
(bool)cPhysics["IsOnGround"] = false;
|
||||
}
|
||||
|
||||
jitterGuard = true;
|
||||
m_PrevPositions[entity] = boxA.Origin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +273,15 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||
size = glm::vec3(1.f, 1.f, 1.f);
|
||||
} else {
|
||||
size = glm::vec3(1.f, 1.6f, 1.f);
|
||||
if (controller->CrouchingLastFrame() && player.HasComponent("Collidable")) {
|
||||
// Disable jitter guard so player doesn't get stuck in the ground.
|
||||
(bool&)player["Collidable"]["JitterGuard"] = false;
|
||||
if (isOnGround) {
|
||||
// The collision should resolve this anyway, but
|
||||
// this is more reliable, since the box gets larger.
|
||||
((glm::vec3&)cTransform["Position"]).y += 0.3f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user