Title pretty much says it all. I’m tryna do an overhead camera of my games map that the user can move around. Map is quite large and with StreamingEnabled means I have to constantly load in segments as the camera moves. And in turn, how can I unload areas the camera isn’t near anymore? As if the player moves their camera around the entire map, it ends up loading every single part and never unloading them, thus causing lag
self.Trove:Connect(RunService.Heartbeat, function()
local MouseLocation = UserInputService:GetMouseLocation()
if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
if self.LastMouseLocation then
local Delta = self.LastMouseLocation - MouseLocation
Camera.CFrame += Camera.CFrame.RightVector * (Delta.X / 2)
Camera.CFrame += Camera.CFrame.UpVector * (-Delta.Y / 2)
end
end
self.LastMouseLocation = MouseLocation
local MinCorner = self.MinPoint
local MaxCorner = self.MaxPoint
local CameraPosition = Camera.CFrame.Position
Camera.CFrame = (Camera.CFrame - Camera.CFrame.Position)
+ Vector3.new(
math.clamp(CameraPosition.X, MinCorner.X, MaxCorner.X),
math.clamp(CameraPosition.Y, MinCorner.Y, MaxCorner.Y),
math.clamp(CameraPosition.Z, MinCorner.Z, MaxCorner.Z)
)
task.spawn(function()
Player:RequestStreamAroundAsync(CameraPosition - Vector3.new(0, DistanceFromGroundToMarker, 0))
end)
end)
I’d recommend using a system where it tracks the last position it requested and then request again once the camera gets far enough away from the position.
Roblox will determine when to unload the parts, so you shouldn’t need to worry about that
Problem with this is it’s server side and needs to relate to a specific part. I don’t wanna make 100 odd parts in the sky to handle replication focus + making the server do all the work. Unless I’m missing something here?
It’s not giving the server any extra work because by default the streaming focus is set to the character, which allows the server to determine when to send the map data to the player. Also, isn’t there only one camera per player? You shouldn’t need to make a bunch of parts for this. If you don’t like that solution then what I said in the other message should work.
Problem I’m facing with the first solution, is I can just magnitude check if far enough to load out, put if I move around the entire map it loads everything and it’s not unloading it at all, even when I exit the camera back to the player, the whole map stays loaded in
There’s not really anything you can do about that unless you change the min/max streaming distance properties on the workspace. Roblox handles when instances get streamed out automatically.
If your game is lagging that bad from the map maybe you should look into optimizing that as well
Is there a better solution to my problem? Worst case I’m looking at just teleporting the character under the camera just so normal streaming behaviour occurs
I’ve already given all the solutions I can think of. StreamingFocus is already the default behavior, so hooking up the camera to a part on the server would probably give you the best results.