From 04057fd8737c9b5b8993500ce3803fd1d1146b33 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Tue, 22 Nov 2022 02:12:15 -0800 Subject: [PATCH] Missile velocity fix --- build_release.bat | 1 + flight.rdbg | Bin 1435 -> 1196 bytes gamestate.c | 14 +++++++------- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/build_release.bat b/build_release.bat index 0265510..3e9df40 100644 --- a/build_release.bat +++ b/build_release.bat @@ -1,2 +1,3 @@ +call shadergen.bat set compileopts=/Fe"flight_release" /O2 call build_msvc.bat \ No newline at end of file diff --git a/flight.rdbg b/flight.rdbg index f805329acbb0de2660c566c281716bef2333b948..9ea0917e3ff4a8576ce9d41c6de35ed7bfeb81d7 100644 GIT binary patch delta 66 zcmbQuy@qqcW@cGN1_lOEAkN88PRxl<&d? delta 255 zcmZ3(Ih%XKX6AY>1_lORAWqFoElRJ9FUgNjOiAGY3IJI-sfk5-LO^zWak^evVoqjC zVo7RzYEe;s5j$8#eoj(i5etx+l%G<`2&4=6fJAX>Vo7{vUU6nhYJ7g0EKo!vxxfji zLQ4}>O4lyQ1}H2BQsJ6cl34;&VNhY@Y-(&|>0)4PZXgYmNiWtb$VseBEh>)At&E2- zfu^UVR>V%ez+A(~H93$)esThf02nK>;Y1S!$>y=Jaj^l-bIZw0&nN)^`BO;d diff --git a/gamestate.c b/gamestate.c index 2d5fba4..492ec7c 100644 --- a/gamestate.c +++ b/gamestate.c @@ -206,13 +206,13 @@ void box_remove_from_boxes(GameState *gs, Entity *box) V2 player_vel(GameState *gs, Entity *e); V2 entity_vel(GameState *gs, Entity *e) { - assert(e->is_box || e->is_player || e->is_grid || e->is_explosion); + assert(e->is_box || e->is_player || e->body != NULL || e->is_explosion); if (e->is_box) return box_vel(e); if (e->is_player) return player_vel(gs, e); - if (e->is_grid) - return grid_vel(e); + if (e->body != NULL) + return cp_to_v2(cpBodyGetVelocity(e->body)); if (e->is_explosion) return e->explosion_vel; assert(false); @@ -244,11 +244,11 @@ static void on_missile_shape(cpShape *shape, cpContactPointSet *points, void *da // lookahead by their velocity V2 rel_velocity = V2sub(entity_vel(gs, other), entity_vel(gs, launcher)); float dist = V2dist(entity_pos(other), entity_pos(launcher)); - - float time_of_travel = sqrtf( (2.0f * dist) / (MISSILE_BURN_FORCE/MISSILE_MASS) ); - + + float time_of_travel = sqrtf((2.0f * dist) / (MISSILE_BURN_FORCE / MISSILE_MASS)); + V2 other_future_pos = V2add(entity_pos(other), V2scale(rel_velocity, time_of_travel)); - + V2 adjusted_to = V2sub(other_future_pos, entity_pos(launcher)); to_face = V2angle(adjusted_to);