From 6f1b0830762b660c31893046899350a7c78d3995 Mon Sep 17 00:00:00 2001 From: fnicon Date: Sun, 22 Mar 2026 00:56:19 +0900 Subject: [PATCH] fix movement --- game/include/lua_api.h | 2 +- game/love_src/src/system/racing_force.lua | 11 ++++++----- game/love_src/src/world/top_down_race/init.lua | 10 +++++----- .../src/world/top_down_race/system/velocity.lua | 10 ++++++---- game/main.lua | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/game/include/lua_api.h b/game/include/lua_api.h index 4cc3915..52fbfea 100644 --- a/game/include/lua_api.h +++ b/game/include/lua_api.h @@ -13,7 +13,7 @@ extern "C" { void draw_quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4); - void set_sphere(float x, float y, float angle); + void set_sphere(float x, float y, float vx, float vy); #ifdef __cplusplus } #endif diff --git a/game/love_src/src/system/racing_force.lua b/game/love_src/src/system/racing_force.lua index e9f3c49..3489c09 100644 --- a/game/love_src/src/system/racing_force.lua +++ b/game/love_src/src/system/racing_force.lua @@ -140,12 +140,13 @@ local function force_workflow( weight_centrifugal ) local val = add_desire(desire_forward, desire_steer, weight_forward, weight_steer) - val = add_friction(val, grip, friction, weight_tire, weight_floor) - val = add_drag(val, drag, streamline, weight_drag_boost) - val = add_drag(val, drag_movement, streamline, weight_drag_halt) + if (val[1] ~= 0 and val[2] ~= 0) then + val = add_friction(val, grip, friction, weight_tire, weight_floor) + val = add_drag(val, drag, streamline, weight_drag_boost) + val = add_drag(val, drag_movement, streamline, weight_drag_halt) + val = add_centrifugal(val, mass, inertia_force, weight_centrifugal) + end val = add_inertia(val, inertia_force, weight_inertia) - val = add_centrifugal(val, mass, inertia_force, weight_centrifugal) - return val end diff --git a/game/love_src/src/world/top_down_race/init.lua b/game/love_src/src/world/top_down_race/init.lua index 5c41d3f..24dc2d0 100644 --- a/game/love_src/src/world/top_down_race/init.lua +++ b/game/love_src/src/world/top_down_race/init.lua @@ -34,12 +34,12 @@ function wrapper:load(_args) velocity = {0.0, 0.0}, max_speed = 10.0, - accel = 10.0, - brake = 10.0, - grip = 10.0, - steer = 10.0, + accel = 2.0, + brake = 1.0, + grip = 1.0, + steer = 1.0, inertia = {0.0, 0.0}, - mass = 10.0, + mass = 1.0, streamline = 1.0 } } diff --git a/game/love_src/src/world/top_down_race/system/velocity.lua b/game/love_src/src/world/top_down_race/system/velocity.lua index 2912a68..65014a3 100644 --- a/game/love_src/src/world/top_down_race/system/velocity.lua +++ b/game/love_src/src/world/top_down_race/system/velocity.lua @@ -154,8 +154,8 @@ local magic_w = { steer = 1.0, drag_boost = 1.0, drag_halt = 1.5, - inertia = 1.0, - centrifugal = 1.0, + inertia = 0.001, + centrifugal = 0.001, drag_movement = 1.0 -- magic_slowdown = 10.0, -- magic_boost = 10000.0, @@ -176,9 +176,9 @@ local function handle_input(accel, brake, steer) desire_forward = - brake end if (left) then - desire_steer = - steer - elseif (right) then desire_steer = steer + elseif (right) then + desire_steer = - steer end return desire_forward, desire_steer end @@ -218,6 +218,8 @@ function system:update(dt) local a = force * dt / mass e[race.dict.velocity].data = e[race.dict.velocity].data + a + e[race.dict.velocity].data[1] = vm.clamp(e[race.dict.velocity].data[1], -max_speed, max_speed) + e["race.pos"].data = e["race.pos"].data + e[race.dict.velocity].data -- local new_velocity = racing_phy.accelerate(dt, 1, velocity, max_speed, f_forward*dt/mass, 0) diff --git a/game/main.lua b/game/main.lua index d23d7a2..8283575 100644 --- a/game/main.lua +++ b/game/main.lua @@ -267,7 +267,7 @@ function love.run() local time = love.timer.getTime() --update(time) test.update(time) - local dt = last_time - time + local dt = time - last_time last_time = time love_update(dt)