mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 13:31:49 +00:00
fix ceiling collision & feat: stepping on solid entity
This commit is contained in:
parent
c8e884009b
commit
ed9ceb26ba
1 changed files with 36 additions and 20 deletions
|
|
@ -193,7 +193,7 @@ static bool calc_collision_neg(
|
||||||
scale[nz] = 1.0f - E * 2.0f;
|
scale[nz] = 1.0f - E * 2.0f;
|
||||||
boxAABB.scale(scale);
|
boxAABB.scale(scale);
|
||||||
boxAABB = boxAABB + offset;
|
boxAABB = boxAABB + offset;
|
||||||
boxAABB.b.y -= stepHeight;
|
boxAABB.b.y -= stepHeight + E * 2;
|
||||||
|
|
||||||
if (const auto aabb = chunks.isObstacleAt(coord.x, coord.y, coord.z, boxAABB)) {
|
if (const auto aabb = chunks.isObstacleAt(coord.x, coord.y, coord.z, boxAABB)) {
|
||||||
float newx = std::floor(coord[nx]) + half[nx] + aabb->max()[nx] + E;
|
float newx = std::floor(coord[nx]) + half[nx] + aabb->max()[nx] + E;
|
||||||
|
|
@ -287,7 +287,7 @@ static void calc_collision_pos(
|
||||||
scale[nz] = 1.0f - E * 2.0f;
|
scale[nz] = 1.0f - E * 2.0f;
|
||||||
boxAABB.scale(scale);
|
boxAABB.scale(scale);
|
||||||
boxAABB = boxAABB + offset;
|
boxAABB = boxAABB + offset;
|
||||||
boxAABB.b.y -= stepHeight;
|
boxAABB.b.y -= stepHeight + E * 2;
|
||||||
|
|
||||||
if (const auto aabb = chunks.isObstacleAt(coord.x, coord.y, coord.z, boxAABB)) {
|
if (const auto aabb = chunks.isObstacleAt(coord.x, coord.y, coord.z, boxAABB)) {
|
||||||
float newx = std::floor(coord[nx]) - half[nx] + aabb->min()[nx] - E;
|
float newx = std::floor(coord[nx]) - half[nx] + aabb->min()[nx] - E;
|
||||||
|
|
@ -327,6 +327,29 @@ void PhysicsSolver::calcCollisions(
|
||||||
hitbox.grounded = true;
|
hitbox.grounded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vel.y > 0.0f){
|
||||||
|
AABB boxAABB = AABB(-half, +half);
|
||||||
|
boxAABB.scale(glm::vec3(1.0f - E * 2, 1.0f + E * 2, 1.0f - E * 2));
|
||||||
|
boxAABB = boxAABB.translated(pos);
|
||||||
|
|
||||||
|
for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) {
|
||||||
|
float x = (pos.x-half.x+E) + ix;
|
||||||
|
for (int iz = 0; iz <= glm::ceil((half.z-E)*2); iz++) {
|
||||||
|
float z = (pos.z-half.z+E) + iz;
|
||||||
|
float y = (pos.y+half.y+E) + 0.5f;
|
||||||
|
if (auto aabb = chunks.isObstacleAt(x,y,z, boxAABB)){
|
||||||
|
float newy = std::floor(y) - half.y + aabb->min().y - E;
|
||||||
|
if (pos.y > newy) {
|
||||||
|
vel.y = 0.0f;
|
||||||
|
pos.y = newy;
|
||||||
|
hitbox.collided[1] = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int axis = 0; axis < 3; axis++) {
|
for (int axis = 0; axis < 3; axis++) {
|
||||||
if (hitbox.collided[axis]) {
|
if (hitbox.collided[axis]) {
|
||||||
pos[axis] = prevPos[axis];
|
pos[axis] = prevPos[axis];
|
||||||
|
|
@ -353,24 +376,17 @@ void PhysicsSolver::calcCollisions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// succesfully increasing code duplication
|
||||||
if (vel.y > 0.0f){
|
for (const auto& box : solidHitboxes) {
|
||||||
AABB boxAABB = AABB(-half, +half);
|
if (glm::distance2(box->position, pos) < E) {
|
||||||
boxAABB.scale(glm::vec3(1.0f - E* 2, 1.0f, 1.0f - E * 2));
|
continue;
|
||||||
boxAABB = boxAABB.translated(pos);
|
}
|
||||||
|
auto boxhalf = box->getHalfSize();
|
||||||
for (int ix = 0; ix <= glm::ceil((half.x-E)*2); ix++) {
|
if (AABB(box->position - boxhalf, box->position + boxhalf).intersects(AABB(pos - half, pos + half))) {
|
||||||
float x = (pos.x-half.x+E) + ix;
|
vel.y = 0.0f;
|
||||||
for (int iz = 0; iz <= glm::ceil((half.z-E)*2); iz++) {
|
float newx = box->position.y + boxhalf.y + half.y;
|
||||||
float z = (pos.z-half.z+E) + iz;
|
if (newx - pos.y <= 0.5f) {
|
||||||
float y = (pos.y+half.y+E);
|
pos.y = newx;
|
||||||
if (auto aabb = chunks.isObstacleAt(x,y,z, boxAABB)){
|
|
||||||
vel.y = 0.0f;
|
|
||||||
float newy = std::floor(y) - half.y + aabb->min().y - E;
|
|
||||||
if (std::abs(newy-pos.y) <= 0.0f) {
|
|
||||||
pos.y = newy;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue