I have been thinking about how to implement camera "anchors". I don't know if there's an established name for them, but what I mean are some constraints in the level data that restrict/control the movement of camera in some way. The main use case (for me) would be to limit the camera's movement in vertical/horizontal sections of a level. I'd prefer having a flexible system instead of hardcoding the lock conditions into the levels.
Here's the basic idea of what I'm talking about: (Blue rectangle is the camera. Red line segments limit the camera's movement.)
anchor.png [ 40.11 KiB | Viewed 1699 times ]
My current idea is to simply store the horizontal and vertical line segments (as seen in the picture) sorted (similar to objects), and check them against the camera extents as the camera moves. Being able to specify the normal of the line segment might be useful as well (i.e. allow movement from one side but not from the other). I would also like to have dynamic control over the constraints (e.g. to make it possible for the player to access a new part of the level conditionally).
There are some potential problems with the above idea, like how the camera should align itself to that vertical section in the bottom of the picture when the player starts moving upwards. Maybe the constraints should be "soft" instead of "hard" (on case-by-case basis?), so that the camera is allowed to move upwards into the wall, but then starts slowly centering itself on the vertical opening.
Or maybe I'm overthinking this and should just go with a simple system that switches the camera's behavior based on player's (or camera's) position, or when the player touches certain objects.
The question is, have any of you implemented a system like this? How did you go about it? Of course ideas in general are welcome as well. This is on NES, so performance is naturally important.
Here's the basic idea of what I'm talking about: (Blue rectangle is the camera. Red line segments limit the camera's movement.)
Attachment:
anchor.png [ 40.11 KiB | Viewed 1699 times ]
My current idea is to simply store the horizontal and vertical line segments (as seen in the picture) sorted (similar to objects), and check them against the camera extents as the camera moves. Being able to specify the normal of the line segment might be useful as well (i.e. allow movement from one side but not from the other). I would also like to have dynamic control over the constraints (e.g. to make it possible for the player to access a new part of the level conditionally).
There are some potential problems with the above idea, like how the camera should align itself to that vertical section in the bottom of the picture when the player starts moving upwards. Maybe the constraints should be "soft" instead of "hard" (on case-by-case basis?), so that the camera is allowed to move upwards into the wall, but then starts slowly centering itself on the vertical opening.
Or maybe I'm overthinking this and should just go with a simple system that switches the camera's behavior based on player's (or camera's) position, or when the player touches certain objects.
The question is, have any of you implemented a system like this? How did you go about it? Of course ideas in general are welcome as well. This is on NES, so performance is naturally important.