Since I’ve seen several people in the forum looking to make a very adjustable camera system, I started working on this example that I shelved several months ago. It’s a little complex to set up, but it will allow a lot more customization with the camera. There are a few more ideas I may be able to add later on, but the overall example is finished.
- Copy and Import the code in the camera+, cam bound 1, and cam bound 2 objects.
- The “Cam Bound” corner objects have to be set by having the NAME be a LETTER and NUMBER
(example: A1, A2, B1, B2, C1, C2, etc.).
- Rooms with layouts bigger than the screen will ease to the edges of the Room.
- Rooms that are the same size of the screen will not move.
- Rooms that are smaller than the screen will only fix to center to the small room.
- You can have smaller rooms inside bigger rooms.
(This also means for any rooms that overlap, the smaller room will be chosen)
- If the player is outside the set areas, the camera will center on the player.
How it works
The corner objects are named by the area that they represent, there is no specific order these need to be in. Using math, I set an ID to each corner.
A1 = 1
A2 = 2
B1 = 3
B2 = 4
C1 = 5
The Camera object then sends a signal by using a global to get each corner’s X and Y values, that then gets put into a list Global. The repeater of the signal is set to 52, so 26 areas are usable by default (one fore each letter of the alphabet). The positions are combined before going into the list, so A1 and A2 has a combined index that looks like “X1.Y1.X2.Y2”. Now each index in this list represents an Area of the map. I also put these values into a separate expression to get the size of each area, that also goes into a separate List Global. I will now be calling these areas “rooms”
With the player’s location, I can scan through the entire list and see what room(s) the player is in. If there are rooms inside of rooms, then the room with the smallest area will be selected. After finding what room we are using, I check the size again to set the camera bounds restrictions.
If the room is the same size as the screen or bigger, the camera bounds will be set to the edges of the room. If the Room is smaller than the screen, then I subtract the bounds and find the center point of the room and the camera would be fixed there. If the player is outside all the rooms, then the bounds are set 1024 away from the player (32x32), and that is updated every frame.
End the end, this is all just to control where the camera is allowed to go, the camera is always trying to ease to the player. If I Flip where the interpolation bundle is compared to the camera boundaries bundle, then the camera would be snappy between room transitions.
If you have any bug reports, suggestion or thoughts, let me know.