For my 2D platformer game I am using the camera function and I was wondering if there is a way to get the camera to not go above or below a certain height when it is following a game object. For example if the player falls off the map I want the player to fall down but the camera to not follow so the player can’t see under the map.
I think the solution is to not attach the camera to the player game object and instead update the position of the camera to match the player position, but ignore y/vertical position.
I want it to do the vertical position within a boundary but not go out of those is that possible?
If you control the position of the camera every frame, with the camera on a separate game object then you’re in full control. Example:
-- camera.script
-- get player position
-- use this as the base of the camera position
local pos = go.get_position("player")
-- keep camera position within 0-1000
if pos.y < 0 then
pos.y = 0
elseif pos.y > 1000 then
pos.y = 1000
end
-- update camera position
go.set_position(pos)
1 Like
Thank you