improve move system

isolation_bkp/dynres
Dominik Madarász 2021-05-07 17:24:22 +02:00
parent 1ad39ad67e
commit ef2ae5a1e6
3 changed files with 8 additions and 6 deletions

View File

@ -23,7 +23,6 @@ typedef struct {
world_pkt_writer_proc *writer_proc;
} world_data;
static world_data world = {0};
#define WORLD_TRACKER_UPDATE_MS 100

View File

@ -4,16 +4,15 @@
#include "modules/physics.h"
#include "zpl.h"
// TODO(zaklaus): move to physics
#define CTRL_DRAG_FACTOR 0.20
void MovementImpulse(ecs_iter_t *it) {
Input *in = ecs_column(it, Input, 1);
Velocity *v = ecs_column(it, Velocity, 2);
for (int i = 0; i < it->count; i++) {
v[i].x = zpl_lerp(v[i].x, in[i].x*1000, CTRL_DRAG_FACTOR);
v[i].y = zpl_lerp(v[i].y, in[i].y*1000, CTRL_DRAG_FACTOR);
if (zpl_abs(v[i].x) < 1000.0f)
v[i].x = in[i].x*1000.0;
if (zpl_abs(v[i].x) < 1000.0f)
v[i].y = in[i].y*1000.0;
}
}

View File

@ -2,6 +2,8 @@
#include "world/world.h"
#include "zpl.h"
#define PHY_WALK_DRAG 0.02
void MoveWalk(ecs_iter_t *it) {
Position *p = ecs_column(it, Position, 1);
Velocity *v = ecs_column(it, Velocity, 2);
@ -10,6 +12,8 @@ void MoveWalk(ecs_iter_t *it) {
// TODO: handle collisions
p[i].x += v[i].x * it->delta_time;
p[i].y += v[i].y * it->delta_time;
v[i].x = zpl_lerp(v[i].x, 0.0f, PHY_WALK_DRAG);
v[i].y = zpl_lerp(v[i].y, 0.0f, PHY_WALK_DRAG);
librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0));
}
}