make camera look visually nicer

This commit is contained in:
bgkillas 2024-10-15 17:01:22 -04:00
parent f281e2ddbf
commit 2f7230377c
2 changed files with 30 additions and 7 deletions

View file

@ -171,13 +171,21 @@ local function player_died()
rpc.add_nickname_change_cursor()
end
local function set_camera_free(enable)
local cam = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PlatformShooterPlayerComponent")
if cam ~= nil then
ComponentSetValue2(cam, "center_camera_on_this_entity", not enable)
ComponentSetValue2(cam, "move_camera_with_aim", not enable)
end
end
local function do_game_over(message)
net.proxy_notify_game_over()
ctx.run_ended = true
local damage_model = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "DamageModelComponent")
GameRemoveFlagRun("ew_flag_notplayer_active")
if damage_model ~= nil and #(EntityGetAllChildren(ctx.my_player.entity) or {}) ~= 0 then
GameSetCameraFree(true)
set_camera_free(true)
GameRemoveFlagRun("ew_cam_wait")
ctx.my_player.entity = end_poly_effect(ctx.my_player.entity)
polymorph.switch_entity(ctx.my_player.entity)
@ -190,7 +198,7 @@ local function do_game_over(message)
GameTriggerGameOver()
end
else
GameSetCameraFree(true)
set_camera_free(true)
GameTriggerGameOver()
end
end

View file

@ -78,6 +78,21 @@ local function get_me()
return alive
end
local function set_camera_free(enable)
local cam = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PlatformShooterPlayerComponent")
if cam ~= nil then
ComponentSetValue2(cam, "center_camera_on_this_entity", not enable)
ComponentSetValue2(cam, "move_camera_with_aim", not enable)
end
end
local function set_camera_pos(x, y)
local cam = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PlatformShooterPlayerComponent")
if cam ~= nil then
ComponentSetValue2(cam, "mDesiredCameraPos", x, y)
end
end
local function target()
if cam_target.entity == ctx.my_player.entity and not EntityHasTag(ctx.my_player.entity, "ew_notplayer") then
perks_ui(true)
@ -96,10 +111,10 @@ local function target()
GameRemoveFlagRun("ew_cam_wait")
async(function()
wait(1)
GameSetCameraFree(false)
set_camera_free(false)
end)
else
GameSetCameraFree(false)
set_camera_free(false)
end
if camera_target == nil then
camera_target = ctx.my_player
@ -121,7 +136,7 @@ local function target()
end
return
end
GameSetCameraFree(true)
set_camera_free(true)
if cam_target == nil or not EntityGetIsAlive(cam_target.entity) then
return
end
@ -141,12 +156,12 @@ local function target()
local dx, dy = t_x - my_x, t_y - my_y
local di = dx * dx + dy * dy
if di > 256 * 256 then
GameSetCameraPos(to_x, to_y)
set_camera_pos(to_x, to_y)
else
local cos, sin = dx / 512, dy / 512
local d = math.sqrt(di)
dx, dy = d * cos, d * sin
GameSetCameraPos(my_x + dx, my_y + dy)
set_camera_pos(my_x + dx, my_y + dy)
end
if camera_target == nil then
camera_target = ctx.my_player