improve move system
parent
1ad39ad67e
commit
ef2ae5a1e6
|
@ -23,7 +23,6 @@ typedef struct {
|
||||||
world_pkt_writer_proc *writer_proc;
|
world_pkt_writer_proc *writer_proc;
|
||||||
} world_data;
|
} world_data;
|
||||||
|
|
||||||
|
|
||||||
static world_data world = {0};
|
static world_data world = {0};
|
||||||
|
|
||||||
#define WORLD_TRACKER_UPDATE_MS 100
|
#define WORLD_TRACKER_UPDATE_MS 100
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
#include "modules/physics.h"
|
#include "modules/physics.h"
|
||||||
#include "zpl.h"
|
#include "zpl.h"
|
||||||
|
|
||||||
// TODO(zaklaus): move to physics
|
|
||||||
#define CTRL_DRAG_FACTOR 0.20
|
|
||||||
|
|
||||||
void MovementImpulse(ecs_iter_t *it) {
|
void MovementImpulse(ecs_iter_t *it) {
|
||||||
Input *in = ecs_column(it, Input, 1);
|
Input *in = ecs_column(it, Input, 1);
|
||||||
Velocity *v = ecs_column(it, Velocity, 2);
|
Velocity *v = ecs_column(it, Velocity, 2);
|
||||||
|
|
||||||
for (int i = 0; i < it->count; i++) {
|
for (int i = 0; i < it->count; i++) {
|
||||||
v[i].x = zpl_lerp(v[i].x, in[i].x*1000, CTRL_DRAG_FACTOR);
|
if (zpl_abs(v[i].x) < 1000.0f)
|
||||||
v[i].y = zpl_lerp(v[i].y, in[i].y*1000, CTRL_DRAG_FACTOR);
|
v[i].x = in[i].x*1000.0;
|
||||||
|
if (zpl_abs(v[i].x) < 1000.0f)
|
||||||
|
v[i].y = in[i].y*1000.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#include "world/world.h"
|
#include "world/world.h"
|
||||||
#include "zpl.h"
|
#include "zpl.h"
|
||||||
|
|
||||||
|
#define PHY_WALK_DRAG 0.02
|
||||||
|
|
||||||
void MoveWalk(ecs_iter_t *it) {
|
void MoveWalk(ecs_iter_t *it) {
|
||||||
Position *p = ecs_column(it, Position, 1);
|
Position *p = ecs_column(it, Position, 1);
|
||||||
Velocity *v = ecs_column(it, Velocity, 2);
|
Velocity *v = ecs_column(it, Velocity, 2);
|
||||||
|
@ -10,6 +12,8 @@ void MoveWalk(ecs_iter_t *it) {
|
||||||
// TODO: handle collisions
|
// TODO: handle collisions
|
||||||
p[i].x += v[i].x * it->delta_time;
|
p[i].x += v[i].x * it->delta_time;
|
||||||
p[i].y += v[i].y * 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));
|
librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue