pixel?
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include "entity.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/tileset/tileset_entities.h"
|
||||
#include "time/time.h"
|
||||
#include "util/math.h"
|
||||
|
||||
@@ -51,16 +50,57 @@ void entityUpdate(entity_t *entity) {
|
||||
playerMovement(entity);
|
||||
}
|
||||
|
||||
// Add velcoity
|
||||
glm_vec3_muladds(entity->velocity, TIME.delta, entity->position);
|
||||
// Apply velocity
|
||||
if(
|
||||
entity->velocity[0] != 0.0f ||
|
||||
entity->velocity[1] != 0.0f ||
|
||||
entity->velocity[2] != 0.0f
|
||||
) {
|
||||
entity->position[0] += entity->velocity[0] * TIME.fixedDelta;
|
||||
entity->position[1] += entity->velocity[1] * TIME.fixedDelta;
|
||||
entity->position[2] += entity->velocity[2] * TIME.fixedDelta;
|
||||
|
||||
// Apply friction
|
||||
glm_vec3_muladds(
|
||||
entity->velocity, -ENTITY_FRICTION * TIME.delta, entity->velocity
|
||||
);
|
||||
// Hit test on other entities.
|
||||
entity_t *start = ENTITIES;
|
||||
entity_t *end = &ENTITIES[ENTITY_COUNT];
|
||||
|
||||
// Clamp small velocities to zero
|
||||
if(glm_vec3_norm(entity->velocity) < ENTITY_MIN_VELOCITY) {
|
||||
glm_vec3_zero(entity->velocity);
|
||||
// Our hitbox
|
||||
physicscircle_t self;
|
||||
glm_vec2_copy(entity->position, self.position);
|
||||
self.radius = 0.5f;
|
||||
|
||||
physicscircle_t other;
|
||||
other.radius = self.radius;
|
||||
|
||||
// TODO: what if multiple collisions?
|
||||
do {
|
||||
if(start == entity) continue;
|
||||
if(start->type == ENTITY_TYPE_NULL) continue;
|
||||
glm_vec2_copy(start->position, other.position);
|
||||
|
||||
physicscirclecircleresult_t result;
|
||||
physicsCircleCheckCircle(self, other, &result);
|
||||
|
||||
if(result.hit) {
|
||||
entity->position[0] -= result.normal[0] * result.depth;
|
||||
entity->position[1] -= result.normal[1] * result.depth;
|
||||
break;
|
||||
}
|
||||
} while((start++) != end);
|
||||
|
||||
// Friction (and dampening)
|
||||
glm_vec3_muladds(
|
||||
entity->velocity, -ENTITY_FRICTION * TIME.delta, entity->velocity
|
||||
);
|
||||
|
||||
if(mathAbs(entity->velocity[0]) < ENTITY_MIN_VELOCITY) {
|
||||
entity->velocity[0] = 0.0f;
|
||||
}
|
||||
if(mathAbs(entity->velocity[1]) < ENTITY_MIN_VELOCITY) {
|
||||
entity->velocity[1] = 0.0f;
|
||||
}
|
||||
if(mathAbs(entity->velocity[2]) < ENTITY_MIN_VELOCITY) {
|
||||
entity->velocity[2] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user