mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +00:00
feat: ceiling collision for solid entities
This commit is contained in:
parent
8dd9e42764
commit
e98996e6a9
1 changed files with 17 additions and 1 deletions
|
|
@ -274,7 +274,7 @@ void PhysicsSolver::calcCollisions(
|
||||||
|
|
||||||
if (vel.y > 0.0f){
|
if (vel.y > 0.0f){
|
||||||
AABB boxAABB = AABB(-half, +half);
|
AABB boxAABB = AABB(-half, +half);
|
||||||
boxAABB.scale(glm::vec3(1.0f - E * 2, 1.0f + E * 2, 1.0f - E * 2));
|
boxAABB.scale(glm::vec3(1.0f - E * 4, 1.0f + E * 2, 1.0f - E * 4));
|
||||||
boxAABB = boxAABB.translated(pos);
|
boxAABB = boxAABB.translated(pos);
|
||||||
|
|
||||||
for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) {
|
for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) {
|
||||||
|
|
@ -293,6 +293,22 @@ void PhysicsSolver::calcCollisions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (auto box : solidHitboxes) {
|
||||||
|
if (glm::distance2(box->position, pos) < E) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto boxhalf = box->getHalfSize();
|
||||||
|
if (box->getAABB().intersects(boxAABB)) {
|
||||||
|
float newy = box->position.y - boxhalf.y - half.y;
|
||||||
|
if (pos.y > newy) {
|
||||||
|
pos.y = newy;
|
||||||
|
}
|
||||||
|
if (vel.y > 0.0f) {
|
||||||
|
vel.y = 0.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int axis = 0; axis < 3; axis++) {
|
for (int axis = 0; axis < 3; axis++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue