when the closest object changes, the position breaks

This commit is contained in:
2025-11-28 23:06:56 -07:00
parent 0bafe2cabd
commit 3923d711dc
+10 -10
View File
@@ -127,8 +127,8 @@ local player_ship = {
-- player_ship.orbital_radius = math.sqrt(player_ship.position_x^2 + player_ship.position_y^2)
-- player_ship.rotation_offset = math.atan2(player_ship.position_y, player_ship.position_x)
-- TODO this just needs to be a list of all objects - including the player
local resource_points = {} -- NOTE they're "planets" but I intend for them to be multiple things tbh
-- TODO this needs to be a list of all objects - including the player
local resource_points = {}
local function make_resource_point(x, y)
local current_object = {
position_x = x or love.math.random() * screen_width / 2,
@@ -140,7 +140,7 @@ local function make_resource_point(x, y)
cargo_contents = {},
}
current_object.orbital_radius = math.sqrt(current_object.position_x^2 + current_object.position_y^2)
-- pretty sure this offset is only correct because game_time starts at 0
-- this offset is only correct because game_time starts at 0
current_object.rotation_offset = math.atan2(current_object.position_y, current_object.position_x)
-- exclude orbits that would collide
local closest_object, distance_to_orbit = get_closest_orbit(resource_points, current_object)
@@ -235,22 +235,22 @@ function love.update(dt)
player_ship.position_y = player_ship.position_y + player_ship.velocity_y * dt
if player_ship.velocity_x == 0 and player_ship.velocity_y == 0 then
player_ship.orbital_radius = player_ship.orbital_radius or math.sqrt(player_ship.position_x^2 + player_ship.position_y^2)
local closest_object, distance_squared_to_object = get_closest_object(resource_points, player_ship)
player_ship.orbital_radius = player_ship.orbital_radius or math.sqrt(distance_squared_to_object)
if not player_ship.rotation_offset then
-- TEMP still locked to core_object
local argument = game_time / player_ship.orbital_radius^1.337 * orbital_speed_constant * core_object.radar_size^2
local argument = game_time / player_ship.orbital_radius^1.337 * orbital_speed_constant * closest_object.radar_size^2
if (argument == math.huge) or (argument ~= argument) then
argument = 0
end
player_ship.rotation_offset = math.atan2(player_ship.position_y, player_ship.position_x) - argument
-- NOTE the order of subtraction of coordinates might be incorrect
player_ship.rotation_offset = math.atan2(player_ship.position_y - closest_object.position_y, player_ship.position_x - closest_object.position_x) - argument
end
-- TEMP player_ship localed to core_object orbit
local argument = game_time / player_ship.orbital_radius^1.337 * orbital_speed_constant * core_object.radar_size^2 + player_ship.rotation_offset
local argument = game_time / player_ship.orbital_radius^1.337 * orbital_speed_constant * closest_object.radar_size^2 + player_ship.rotation_offset
if (argument == math.huge) or (argument ~= argument) then
argument = 0
end
player_ship.position_x, player_ship.position_y = core_object.position_x + player_ship.orbital_radius * math.cos(argument), core_object.position_y + player_ship.orbital_radius * math.sin(argument)
player_ship.position_x, player_ship.position_y = closest_object.position_x + player_ship.orbital_radius * math.cos(argument), closest_object.position_y + player_ship.orbital_radius * math.sin(argument)
else
player_ship.orbital_radius = nil
player_ship.rotation_offset = nil