mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
feat: new linear damping behaviour
This commit is contained in:
parent
f4e55f9938
commit
06d03f889c
1 changed files with 13 additions and 12 deletions
|
|
@ -30,14 +30,15 @@ static float calc_step_height(
|
|||
AABB aabb(-half, +half);
|
||||
aabb.scale(glm::vec3(1.0f - E * 2, 1.0f, 1.0f - E * 2));
|
||||
aabb = aabb + pos + glm::vec3(0.0f, stepHeight, 0.0f);
|
||||
if (stepHeight > 0.0f) {
|
||||
for (int ix = 0; ix <= glm::ceil((half.x - E) * 2); ix++) {
|
||||
float x = (pos.x - half.x) + ix;
|
||||
for (int iz = 0; iz <= glm::ceil((half.z - E) * 2); iz++) {
|
||||
float z = (pos.z - half.z) + iz;
|
||||
if (chunks.isObstacleAt(x, pos.y + half.y + stepHeight, z, aabb)) {
|
||||
return 0.0f;
|
||||
}
|
||||
if (stepHeight <= 0.0f) {
|
||||
return stepHeight;
|
||||
}
|
||||
for (int ix = 0; ix <= glm::ceil((half.x - E) * 2); ix++) {
|
||||
float x = (pos.x - half.x) + ix;
|
||||
for (int iz = 0; iz <= glm::ceil((half.z - E) * 2); iz++) {
|
||||
float z = (pos.z - half.z) + iz;
|
||||
if (chunks.isObstacleAt(x, pos.y + half.y + stepHeight, z, aabb)) {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -293,11 +294,9 @@ void PhysicsSolver::calcSubstep(
|
|||
int substeps
|
||||
) {
|
||||
if (glm::length2(hitbox.groundVelocity) > 1e-6f) {
|
||||
pos.x += hitbox.groundVelocity.x;
|
||||
if (hitbox.groundVelocity.y < 0.0f) {
|
||||
pos.y += hitbox.groundVelocity.y;
|
||||
}
|
||||
pos.z += hitbox.groundVelocity.z;
|
||||
}
|
||||
|
||||
auto initpos = pos;
|
||||
|
|
@ -386,8 +385,10 @@ void PhysicsSolver::step(
|
|||
float linearDamping = hitbox->linearDamping * hitbox->friction;
|
||||
|
||||
glm::vec3& vel = hitbox->velocity;
|
||||
vel.x /= 1.0f + delta * linearDamping;
|
||||
vel.z /= 1.0f + delta * linearDamping;
|
||||
auto diff = hitbox->groundVelocity / dt - vel;
|
||||
vel.x += diff.x * delta * linearDamping;
|
||||
vel.z += diff.z * delta * linearDamping;
|
||||
|
||||
if (hitbox->verticalDamping > 0.0f) {
|
||||
vel.y /= 1.0f + delta * linearDamping * hitbox->verticalDamping;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue