Camera+ Example - JR01

Camera+ Example

camera+2

Link: https://flowlab.io/game/play/2117959

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.



How to set up Camera+

  • 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.).

How the room layouts work

  • 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
etc.

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.
https://flowlab.io/game/play/2117959

20 Likes

I tried it and it refused to transfer to the next room, I did all the steps correctly though.

2 Likes

This is absolutely amazing, I can see it being used for a lot of dungeon crawlers. None of my shelved ideas involve platformers but I’m sure that for platformer designers this is huge!

2 Likes

I see where I messed up, if you re-import the Camera+ bundle it should work now. Also, I suggest lowering B2, so your player isn’t outside that range.

As well, I want to suggest replacing the sprite of the corner objects, not being centered does affect the exact line where the player has to cross. This would be why it works better when you move B1 and C1 to the left and overlap. Their X and Y positions aren’t centered.

Thanks, this should have more uses for other games too.
There are a lot more potential because it changes depending on how you layout the areas.

4 Likes

Nope, it still does not work.

2 Likes

Your globals are not activating, you have the wrong names set to them.
You have the old global names that were in the first bundle, those are what I removed.

2 Likes

Oh :person_facepalming: I literally just realized that. That is my bad, thank you very much.

3 Likes

Also, before switching to the next area where the Cam Bounds are, the camera does this weird shift. I switches the where the A1 and B1 Cam Bounds are then quickly switches to the current one when moving to the new Cam Bounds.

2 Likes

I took a look at the bounds and it seems you imported the wrong cam bounds for the “cam bound 2” object. That will also will give weird transitions because it’s now it taking the coordinates of the wrong corner of itself.

3 Likes

Ohhhh alright. I am making quite a lot of mistakes. Thank you again.

2 Likes

Question: Can these be used to make small cinematics?

2 Likes

I don’t see why not, but I would maybe have a switch for the player global so you can switch to what has control over the camera.

That also makes me think, should I add an on/off input to the bundle later?
Like it turns off all the areas and just centers on the object.

6 Likes

Definitely, this will add more flexibility to the camera, making it easier to switch how you want the camera to behave.

Example (For my game): When the character enters a boss battle, the camera will switch to two-subject camera.

3 Likes

Update 11/14/22:

  • Fixed spastic camera movement at the start.
  • Added On/Off input
  • Added Remove input
  • Added Re-Add input
  • Re-ordered the wires

The Camera now starts where the camera object is, and then moves to the start once the setup is complete. The On/Off input is a single input for turning on or off the boundaries. With the Bundles set to off, the bundles will always center to the target. The Remove input lets you remove an area in the list so that when reaching that area (like are C or F), the camera doesn’t react when in that area. This only works if there is an Area with that Letter. Re-add input puts the removed area back into the camera list, this only works if you have removed an area.

Turning Off/On the bundle

Camera+onoff

Removing and Re-adding Areas/Rooms

Camera+removeadd

9 Likes

This is amesome work! Is this a game you are planning to make or ya just showing how this camera mechanic works?

2 Likes

Kinda wanna test this in ducky :grin:

2 Likes

Ducky? There is a game about ducks. Sound like fun.

1 Like

Yeah check it out
Link

1 Like

Just showing how the mechanics work.
I have a lot of example like this on my profile, some of which are on the help page too.
https://flowlab.io/users/profile/622236

2 Likes

hello, i’m having an issue where if i the player be able to go in two different directions then the cam bounds created 2nd don’t work and the game just unlocks the camera, here’s a link to the game if that helps https://flowlab.io/game/play/2163698, specifically the camera unlocks when going right

1 Like