Questions Regarding an IoOD/FNaF Style Camera System

Godot Version

4.3

Question

I am sure this is very basic and I’m just dumb, but I’m new to Godot and have to ask this.

I am making a game similar in nature to “I’m on Observation Duty”, but the cameras are giving me trouble.

My idea for a solution was to have each camera connected to its own button, more like Five Nights at Freddy’s, but I am unsure how to code that in.

So, I would like help either with that approach, or the “Left/Right” arrow loop approach IoOD uses.

Have you tried our the Phantom Camera add-on? Seems like you can add multiple cameras and then change the active camera via code. Another way is just saving the camera locations via code (or using Marker3Ds) and move the camera to those positions/rotations as appropriate.

I have not tried Phantom. I’ll absolutely give that a go later.

Before that, I should mention what I have now, to see if you can help with that alone.

I have 5 “Camara3D” objects set up in the 5 positions I want them in, and 5 “Buttons” set up to correspond to each of these cameras.

I want it so if you hit the button labled “Bedroom”, for example, it swapped to the camera associated with the bedroom

The Camera2D and Camera3D node has make_current() which allows you to select which camera is currently active.

For your desired result, you could make a simple script that calls make_current() for a specific camera instance. Here is an example of what I’m describing:

class_name CameraToggle
extends Button

@export var target_camera: Camera3D

func _ready():
	# Connect the function below to the 'pressed'-signal
	pressed.connect(on_pressed)

func on_pressed():
	# Change the current active camera to 'target_camera'
	target_camera.make_current()

The caveat to this simple approach is that your UI must exist in the scene(s) where the cameras exist; the scripts requires the target_camera variable to be set inside the editor before the game is build.

If you want inspiration for a method that is less coupled, you may look at another post similar to this one.


I hope that does it. Let me know if you need help with anything else regarding this issue.

Can you explain more on what the line of code saying “pressed.connect(on_pressed)” is for?

class_name CameraToggle
extends Button

@export var target_camera: Camera3D

func _on_pressed() → void:
$Hallway.make_current($Hallway)

It’s giving me an error stating “Attempting to call function 'make_current” in base ‘null instance’ on a null instance

As described in the comment, this line connects on_pressed() to the pressed signal.

When the button is considered pressed, the button will emit this pressed signal. By connecting our function to this signal, we can create code that is only executed when the button is pressed.

If you don’t know what signals are and how they can be useful, I suggest you read through the documentation:

I am assuming $Hallway is supposed to be a reference to a camera in your scene? You should not be using a constant path (like $Hallway) to reference your camera. Doing this would require you to create one script for every camera-button pair you create – that’s not smart.

The script I proposed uses the @export variable, target_camera, as a reference to the camera that should be activated (via make_current()). Using an @export variable lets you have multiple instances of your script with different configurations. For example:

Node Hierarchy

  • HallwayButton: target_camera = HallwayCamera
  • LoungeButton: target_camera = LoungeCamera
  • GardenButton: target_camera = GardenCamera

As for your error Attempting to call function 'make_current” in base ‘null instance’ on a null instance, a null instance is present when a reference to an object is invalid. For the code you’ve shown, that likely means that $Hallway is not a path that points to any node – it is thus a null instance.


I will be blunt. You don’t seem to be familiar with coding at all. While I am perfectly capable of teaching you the basics, I believe we are both better off if you go through some of the tutorials available online. Godot has its own tutorials in the documentation (see Your first 2D game and Your first 3d game).

That said, I commend you for asking questions and for attempting to modify a simple piece of code – even if it doesn’t work.

The example script I provided does solve your issue so I have nothing more to add. If you have any questions about other things, feel free to send me a message on the forum by clicking on my profile and clicking ‘Message’.

Good luck with your Observation Duty game.