From 6b2f049704b6a03f583c9ec3404af7dc6774ed3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Tue, 27 Jul 2021 15:01:17 +0200 Subject: [PATCH] camera: instant follow on the first entity --- code/game/header/camera.h | 3 +++ code/game/source/camera.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/code/game/header/camera.h b/code/game/header/camera.h index 61dab7f..14776e6 100644 --- a/code/game/header/camera.h +++ b/code/game/header/camera.h @@ -11,6 +11,9 @@ typedef struct { camera_mode mode; uint64_t ent_id; double x, y; + + // HACK(zaklaus): Don't lerp if this is the first time we follow any entity. + bool first_time; } camera; void camera_reset(void); diff --git a/code/game/source/camera.c b/code/game/source/camera.c index ec15240..44800ef 100644 --- a/code/game/source/camera.c +++ b/code/game/source/camera.c @@ -10,6 +10,7 @@ static camera main_camera; void camera_reset(void) { zpl_zero_item(&main_camera); main_camera.mode = CAMERA_MODE_STATIONARY; + main_camera.first_time = true; } void camera_update(void) { @@ -22,6 +23,12 @@ void camera_update(void) { main_camera.x = zpl_lerp(main_camera.x, view->x, CAMERA_LERP_FACTOR); main_camera.y = zpl_lerp(main_camera.y, view->y, CAMERA_LERP_FACTOR); + + if (main_camera.first_time) { + main_camera.first_time = false; + main_camera.x = view->x; + main_camera.y = view->y; + } }break; default: {