so in my game, I have my camera offset like this in customization with a part
basically the camera is pointed at an offset from the character, like how I want.
but when I make the screen shorter… the character starts going offscreen.
I don’t even know where to start to fix this, please help.
2 Likes
Maybe you can check if the players’ screen resolution is a certain size, and if so, move the camera part back.
there’s hundreds of screen sizes for phones and monitor sizes (exaggerated, ik). and sometimes players like to make their windows really small for some reason. I don’t think it would be wise to check for specific screen sizes…
Not specific. Only when their screen size goes below a certain point.
Also, wasn’t your whole point to make the figure still on screen regardless of screen size??
You need to use the aspect ratio to scale some kind of distance value for the camera. You can calculate the aspect ratio by doing ViewportSize.X/ViewportSize.Y
As the screen gets wider, the aspect ratio increases, as the screen gets skinnier (as it approaches a more square shape like your second screenshot, or goes beyond that and becomes a portrait shape) the aspect ratio decreases. In your case you’d want to start zooming out after the aspect ratio becomes less than 1.
Here’s my scuffed recreation:
And here’s a basic example of using aspect ratio to scale the offset of the camera:
-- Services
local RunService = game:GetService("RunService")
-- Objects
local Camera = workspace.CurrentCamera
local CamPart = workspace.CamPart
-- Config
local aspectRatioDistance = 15
workspace.Camera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function()
local aspectRatio = Camera.ViewportSize.Y/Camera.ViewportSize.X
local newCameraCFrame = CamPart.CFrame
local aspectRatioOffset = newCameraCFrame:VectorToWorldSpace(Vector3.new(0, 0, aspectRatioDistance * math.clamp(aspectRatio - 1, 0, 1)))
print(aspectRatioOffset)
workspace.Camera.CFrame = newCameraCFrame + aspectRatioOffset
end)
Here’s how it looks
I’m sure there’s some way to derive the exact offset distance you’d need depending on the camera’s field of view, but playing around with the number until you get something you like works, too.
1 Like
that makes more sense than to check for each individual size like I thought you were implying. the point was, if there is a way, to take the screen size and somehow use it in a way that positions the camera correctly. since the camera is at an angle I can’t just use the X/Z position of the character and an offset which I could divide the screen size.
I’ll mess with it later, but I think that might (almost) be it. will probably have to take the camera rotation into consideration for it to work though since it’s slightly rotated.
1 Like
I used VectorToWorldSpace so that the offset applies on the local Z axis of however the camera is rotated, should work for your camera too.