How to make the camera not go below certain objects

I want to make it so that the camera shouldn’t go below floors but when you’re in the air it should center on your character.

So in this below screenshot, I want it so that the camera doesn’t go below the red lines in you’re in that “room” or place. but i want it to center the player if the player is anywhere in the air or on platforms.

I want this possible to be extended to certain walls as well so when you stand next to a wall it wont center your character but rather show as much of the room as possible.

some games that do this for instance are games like hollow knight where if you stand at a certain wall your character isnt centered and the camera doesnt go below the ground

while when you stand in the middle of a room or platforms in the air it centers your character

I think what i want is for the camera to when it’s in collision with an object not move past that object somehow.

So if the camera Y axis is in collision with a “CameraBarrier” object that’s below us don’t move the camera further down on the Y axis than that object. and same for a “CameraBarrier” object to the left, right or top of us, where the camera shouldnt move further on that x or y axis past the object.
In the example below i’m thinking the green transparent boxes would be the “CameraBarrier” objects

camera

1 Like

you can mod this with conditions when player steps on platform etc

limit being the edges of what you wanna show in a rectangle

Capture

You can try adding an object as a camera tracker then center the camera on that tracker instead of your player, so calculate the distance between the player and the tracker and it’s X/Y and move the tracker down/up when you need so the camera will always follow the tracker.
Here an extension that maybe helps

Couldnt make sense of this what so ever testing it on my project haha.

It just kinda stops the camera from movin at all?

https://streamable.com/0rqhts

that sounds like it might be a bit janky and wont make it as fluid when following a player in the middle of a room?

Ok, I don’t know if this is the effect you want in this game is the implementation with that extension

As you can see the camera follows the trackr but is set to be faster so it seems to follow the player, and the scenarios are revealed as the tracker distance to the player

hm not sure, feels like it’s not exactly like how i imagine it… but not sure if that’s cause of how the game looks and how short all ceilings are :thinking:

image

In this example an issue i can see is that the camera doesnt move on an x axis to the left despite there not being a wall to the left.

I think what i want is for the camera to when it’s in collision with an object not move past that object somehow.

So if the camera Y axis is in collision with a “CameraBarrier” object that’s below us don’t move the camera further down on the Y axis than that object. and same for a “CameraBarrier” object to the left, right or top of us, where the camera shouldnt move further on that x or y axis past the object.
In the example below i’m thinking the green transparent boxes would be the “CameraBarrier” objects

camera

That is because is a camera limit to the stage size and the X/Y movements is to fast you can control the speed of the lerp so the camera moves slowly. I know there is another extension I think is on the Extension inside the GD you can control the speed even the zoom
Edit: [Extension] New AdvancedPlatformCamera Behavior

as far as i see in that example it always centers the character?

i think i might have it uhhh how do you make gif files quick haha

ok so this is what i ended up doing so theres no jank this time and the -280 value just takes into account the platform y size

hopefully it is what your looking for

uh… not sure its working correctly haha

https://streamable.com/rqjtcq

how do you upload the videos i can show u what i got

maybe you have another camera conflicting with it

I mainly just use OBS to record and then just drag the file into a website called https://streamable.com/ and it uploads it there.

Here’s a zip with all the game files and code if you wanna take a closer look Gofile - Free file sharing and storage platform

The lerp speed is insane, you need to make the speed of left to a higher value

in that example the camera is completely still when you’re on the platform that’s not what i want, i still want it to move on the x axis when the character moves i just don’t want it to go below a certain point below it. and to not go past a certain x point when close to a wall.

ooh my bad i didin’t check properly you can just change the x value to the not in collision value it should work then i just tested about the wall part i haven’t worked on it

but it should be the same theory

After some advice over on the discord on not making the scenes too big i’m going with the simpler boundaries solution of this… it didn’t properly “solve” my issue but i feel like i have to if i dont want to hamper performance

I’ve been thinking about this some more and doing some research with more storied game devs than I, and I’m starting to think we can do the “adaptable camera bottom/top based off platforms” from Hollow Knight by using Raycast conditions/actions.

I need to think some more on how to implement it, but watch this space and/or the discord for more info if I come up with a solution.

1 Like