Only apply air friction if the ground is never hit during the frame.

This commit is contained in:
William Moberg
2016-02-08 13:32:45 +01:00
parent 7641ba49c7
commit 6610bb974d
+13 -5
View File
@@ -20,6 +20,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
// Collide against octree items
m_OctreeResult.clear();
m_Octree->ObjectsInSameRegion(*boundingBox, m_OctreeResult);
bool everHitTheGround = false;
for (auto& boxB : m_OctreeResult) {
glm::vec3 resolutionVector;
if (boxA.Entity == boxB.Entity) {
@@ -43,17 +44,24 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
if (Collision::AABBvsTriangles(boxA, model->m_Vertices, model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
(glm::vec3&)cTransform["Position"] += resolutionVector;
cPhysics["Velocity"] = inOutVelocity;
(bool)cPhysics["IsOnGround"] = isOnGround;
} else {
(bool)cPhysics["IsOnGround"] = false;
if (isOnGround) {
everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true;
}
}
} else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
//Enter here if boxB has no Model.
(glm::vec3&)cTransform["Position"] += resolutionVector;
(bool)cPhysics["IsOnGround"] = resolutionVector.y > 0;
if ((bool)cPhysics["IsOnGround"]){
if (resolutionVector.y > 0) {
everHitTheGround = true;
(bool)cPhysics["IsOnGround"] = true;
((glm::vec3&)cPhysics["Velocity"]).y = 0.f;
}
}
}
//This should apply air friction and such, iff zero models were hit.
if (!everHitTheGround) {
(bool)cPhysics["IsOnGround"] = false;
}
}