mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
fix division by zero in some cases
This commit is contained in:
parent
6f195c9a2c
commit
7d09a7957c
2 changed files with 24 additions and 11 deletions
|
|
@ -1,28 +1,29 @@
|
|||
#define VC_ENABLE_REFLECTION
|
||||
#include "Entities.hpp"
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "data/dv_util.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "Entity.hpp"
|
||||
#include "EntityDef.hpp"
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/core/DrawContext.hpp"
|
||||
#include "graphics/core/LineBatch.hpp"
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/render/ModelBatch.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "maths/FrustumCulling.hpp"
|
||||
#include "maths/rays.hpp"
|
||||
#include "EntityDef.hpp"
|
||||
#include "Entity.hpp"
|
||||
#include "rigging.hpp"
|
||||
#include "maths/util.hpp"
|
||||
#include "physics/PhysicsSolver.hpp"
|
||||
#include "rigging.hpp"
|
||||
#include "world/Level.hpp"
|
||||
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <sstream>
|
||||
|
||||
static debug::Logger logger("entities");
|
||||
|
||||
Entities::Entities(Level& level)
|
||||
|
|
@ -336,7 +337,14 @@ void Entities::updatePhysics(float delta) {
|
|||
? 8.0f
|
||||
: (!grounded ? 2.0f : 10.0f);
|
||||
hitbox.scale = transform.size;
|
||||
transform.setPos(hitbox.position);
|
||||
if (util::is_nan_or_inf(hitbox.position)) {
|
||||
logger.error()
|
||||
<< "something bad happened in physics engine (entity "
|
||||
<< eid.def.name << "#" << eid.uid << ")";
|
||||
hitbox.position = transform.pos;
|
||||
} else {
|
||||
transform.setPos(hitbox.position);
|
||||
}
|
||||
if (hitbox.grounded && !grounded) {
|
||||
scripting::on_entity_grounded(
|
||||
*get(eid.uid), glm::length(prevVel - hitbox.velocity)
|
||||
|
|
|
|||
|
|
@ -140,8 +140,10 @@ static bool calc_collision_neg_y(
|
|||
if (pos.y < newy && glm::abs(pos.y - newy) < 0.5f) {
|
||||
pos.y = newy;
|
||||
}
|
||||
hitbox.groundVelocity =
|
||||
(box->position - box->prevPosition) / box->delta;
|
||||
if (glm::abs(box->delta) > 1e-5f) {
|
||||
hitbox.groundVelocity =
|
||||
(box->position - box->prevPosition) / box->delta;
|
||||
}
|
||||
if (vel.y < 0.0f) {
|
||||
vel.y = 0.0f;
|
||||
if (hitbox.groundMaterial.empty()) {
|
||||
|
|
@ -300,6 +302,9 @@ void PhysicsSolver::calcSubstep(
|
|||
) {
|
||||
if (hitbox.grounded) {
|
||||
pos.x += hitbox.groundVelocity.x * dt * substeps;
|
||||
if (hitbox.groundVelocity.y < 0.0f) {
|
||||
pos.y += hitbox.groundVelocity.y * dt * substeps;
|
||||
}
|
||||
pos.z += hitbox.groundVelocity.z * dt * substeps;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue