[Help] Room transition, Zelda-like Camera

Good Evening. After several attempts and following some tutorials, I’m still confused about this problem, even though I have a better understanding of what it is.

(Previous post, with some extra context)

This type of camera has several names, including: room scope camera, room transition camera, Zelda-like camera, or [2D] fixed-position camera.

I’ve watched several tutorials and even tried some things on my own with the little knowledge I have, but it hasn’t worked very well. Maybe it’s a bit of a “skill issue” or something like that. I always end up confused or the code crashes after I mess around with it a little more. I haven’t had much success with this, so I would really appreciate some help. Whether it’s a tutorial link or a comment on the topic, I’m open to anything.

I really don’t want to give up on this camera, but if it’s the only option, I guess I don’t have much choice. Thank you for reading this far, and to everyone who has helped me before and so far. Any further help is appreciated.

Hello, is there a specific thing you need help on? Do you have any code that you’ve written so far? I could make a simple demo for you if you think that you could learn from the code.

1 Like

Sure! But maybe I’d think it’s better restart from zero.

The previous camera script:

extends Camera2D
class_name RoomTransiCamera

const HORIZONTAL_OFFSET : int = 56
const VERTICAL_OFFSET : int = 64

@onready var m_CameraHorizontalMovement : int = get_viewport_rect().size.x - HORIZONTAL_OFFSET
@onready var m_CameraVerticalMovement : int = get_viewport_rect().size.y - VERTICAL_OFFSET

@export var TargetNode : Node2D  = null

var m_CurrentRoom : Vector2 = Vector2.ZERO

var m_OriginOffset : Vector2 = Vector2.ZERO

func _ready():
	m_OriginOffset = TargetNode.get_position()

func _UpdateCameraPosition(direction : Vector2) -> void:
	m_CurrentRoom += direction
	set_position(m_OriginOffset + m_CurrentRoom * Vector2(m_CameraHorizontalMovement, m_CameraVerticalMovement))

func _OnBodyEnteredCima(body):

func _OnBodyEnteredBaixo(body):

func _OnBodyEnteredEsqu(body):

func _OnBodyEnteredDire(body):

The scene so far (“sala” is “room” in portuguese):

This is the best I could do, following this tutorial. Apparently, using collisions in this way is more complicated than “camera bounds.” Some research leads me to believe that there may be a more effective method, but I’m not sure about that.

What issues are you having with the current script?

This one worked pretty well, for a while. But suddenly, it stopped working, and I don’t know why. I think it’s some sort of corrupted file, though. But wait a minute, I’ve found something interesting.

I found a file on an old flash drive. I had tried something similar last year, when I was still planning to make a FAITH fangame. Following this tutorial, I extended the “doors” to the four corners, and I was able to achieve an interesting result, even though the limits didn’t fit well and not all directions worked. I changed a bit of the code, but overall I followed the project almost to the letter.

Taking some of the files of the old project to a new one, I got this error message:

Invalid set index ‘accept_input’ (on base: ‘null instance’) with value of type ‘bool’

Okay if it’s some kind of corrupted file, do you get any errors? Or would you rather I help with restarting the code from scratch instead of troubleshooting the current one?

I believe it will take less time to troubleshoot and debug the issue properly. Of course, I don’t want to take advantage of your goodwill in any way! The main problem here is that the code doesn’t seem to be responding to contact/collision. The only thing I have are these messages. It seems like there’s one for each collision, but I don’t know where the other two at the top come from:

Hi, those are warnings and should not affect the functionality of the game. Can you set a breakpoint (click the gutter to the right of the script to set a breakpoint, a red dot should appear) or a print statement to see if the collision functions are being called?

Sure! But first, are the collision layer right?


Area2D, camera

Also, noticed the camera isn’t centered in the way it should be. What happened there? The position in the scene isn’t right?

a physics layer is something that a physics object exists on. player is assigned to layer 3, so it exists on layer 3. meanwhile, masks mean that the object is looking for other objects that have that layer. so the camera is looking for objects on layer 2, and so cannot find the player because it is on layer 3. you need to change the mask to 3.

also the script of the camera sets the camera’s position to the player’s position at the start, if you don’t want that then you need to change where it is placed in the ready function

1 Like

Thank you very much. Well, despite everything, it still doesn’t seem to be colliding. I set breakpoints in the functions to check, but nothing appeared in the console. Maybe using the “print” method could provide some answers?

put the breakpoints inside the functions, like on the _UpdateCameraPosition line, breakpoints should stop the game, it won’t print anything out

The object did not respond in any direction except for the right. I received 400+ error messages, almost all of which had the same text, except for the first one.

And the last, though it may not be useful.

weird, did you put the breakpoints? what is the code of the function?

Yup. Placed all of them here.

And this is the function.
The full code snippet is up here.

that’s strange, if the game doesn’t automatically stop when it reaches the breakpoint then it must never enter the functions in the first place, i have never seen that specific error before, i will look into it

Thank you very much for your help. I will clone the project and try a few things on my own for now. To me, the strangest thing is that only the right side interacts with the character. The previous attempt had the same problem. Only the right side seems to work. (?)

without seeing your actual camera scene i don’t know why that is, but you don’t seem to have blue collision shapes? are you using collision polygon

Yep, I’m using collision polygons.

And this is my actual camera scene.

Is this the problem?

“Baixo”, “cima”, “esqu” and “dire” = down, up, left and right.