From d9eb9b2bf5c4e83b219bdee6431469e490bc76c1 Mon Sep 17 00:00:00 2001 From: fnicon Date: Sun, 22 Mar 2026 14:13:12 +0900 Subject: [PATCH] kinda work movement --- game/love_src/src/new/components/racer.lua | 38 +++++++++++++++------- game/love_src/src/new/world/race.lua | 6 +++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/game/love_src/src/new/components/racer.lua b/game/love_src/src/new/components/racer.lua index 6c0bbf4..9ebe21c 100644 --- a/game/love_src/src/new/components/racer.lua +++ b/game/love_src/src/new/components/racer.lua @@ -14,7 +14,11 @@ end local default = { pos = vm.vec2(44.64, 10.87), + orientation = vm.vec2(0.0, 0.0), + orientation_speed = vm.vec2(0.0, 0.0), + min_orientation_speed = -1.0, + max_orientation_speed = 1.0, velocity = vm.vec2(0.0, 0.0), max_speed = 1.0, @@ -69,20 +73,28 @@ local function rotate_vector(x0, y0, theta) return vm.vec2(x1, y1) end -local function velocity_flow(dt, force, mass, velocity, max_speed, min_speed) +local function forward_velocity(dt, force, mass, velocity, max_speed, min_speed) if (mass == 0) then mass = 1 end - local a = force * dt / mass - - -- local theta_a = rotate_vector(force[1], 0, force[2]) - local new_velocity = velocity + a - new_velocity[1] = vm.clamp(new_velocity[1], min_speed, max_speed) - new_velocity[2] = vm.clamp(new_velocity[2], min_speed, max_speed) + local a = force[1] * dt / mass + local new_velocity = velocity[1] + a + new_velocity = vm.clamp(new_velocity, min_speed, max_speed) return new_velocity end +local function orientation_velocity(dt, force, mass, orientation_speed, orientation, max_orientation, min_orientation) + if (mass == 0) then + mass = 1 + end + local a = force[2] * dt / mass + local new_speed = orientation_speed + a + new_speed = vm.clamp(new_speed, min_orientation, max_orientation) + local new_orientation = rotate_vector(orientation[1], orientation[2], new_speed) + return new_orientation, new_speed +end + function world:update_race(dt) local x, y = self.data.pos[1], self.data.pos[2] local or_x, or_y = self.data.orientation[1], self.data.orientation[2] @@ -103,10 +115,14 @@ function world:update_race(dt) magic_w.drag_boost, magic_w.drag_halt, magic_w.inertia, magic_w.centrifugal ) - self.data.velocity = velocity_flow(dt, force, mass, velocity, max_speed, min_speed) + local f_v = forward_velocity(dt, force, mass, velocity, max_speed, min_speed) + local o, o_v = orientation_velocity(dt, force, mass, self.data.orientation_speed, self.data.orientation, self.data.max_orientation_speed, self.data.min_orientation_speed) + self.data.velocity[1] = f_v + self.data.orientation_speed = o_v + self.data.orientation = o -- if (self.data.velocity[1] ~= 0) then - self.data.pos = self.data.pos + self.data.velocity + self.data.pos = self.data.pos + o * f_v -- end self.data.inertia = force @@ -119,7 +135,7 @@ end function world:draw() local x, y = self.data.pos[1], self.data.pos[2] local or_x, or_y = self.data.orientation[1], self.data.orientation[2] - local vx, vy = self.data.velocity[1], self.data.velocity[2] + local vx, vy = self.data.orientation[1] * self.data.velocity[1], self.data.orientation[2] * self.data.velocity[1] test.set_sphere(x, y, vx, vy) end @@ -144,7 +160,7 @@ function world:ui_draw() debug_data(650, 0, 1.0, 0.0, 1.0, self.data) debug_data(650, 400, 1.0, 0.0, 1.0, magic_w) - local vx, vy = self.data.velocity[1], self.data.velocity[2] + local vx, vy = self.data.orientation[1], self.data.orientation[2] debug_vector(vx, vy) end diff --git a/game/love_src/src/new/world/race.lua b/game/love_src/src/new/world/race.lua index 36f13e1..0536216 100644 --- a/game/love_src/src/new/world/race.lua +++ b/game/love_src/src/new/world/race.lua @@ -24,7 +24,11 @@ local entities_default = { data = { racer = { pos = vm.vec2(44.64, 10.87), - orientation = vm.vec2(0.0, 0.0), + + orientation = vm.vec2(1.0, 0.0), + orientation_speed = 0.0, + min_orientation_speed = -1.0, + max_orientation_speed = 1.0, velocity = vm.vec2(0.0, 0.0), max_speed = 1.0,