From ef2ae5a1e6d2277b5fad3b0fff818d5463e1f3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Fri, 7 May 2021 17:24:22 +0200 Subject: [PATCH] improve move system --- code/common/world/world.c | 1 - code/modules/source/controllers.c | 9 ++++----- code/modules/source/physics.c | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/code/common/world/world.c b/code/common/world/world.c index ca91494..59eac69 100644 --- a/code/common/world/world.c +++ b/code/common/world/world.c @@ -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 diff --git a/code/modules/source/controllers.c b/code/modules/source/controllers.c index f33f850..89d8735 100644 --- a/code/modules/source/controllers.c +++ b/code/modules/source/controllers.c @@ -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; } } diff --git a/code/modules/source/physics.c b/code/modules/source/physics.c index 59520ca..8497526 100644 --- a/code/modules/source/physics.c +++ b/code/modules/source/physics.c @@ -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)); } }