This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

enter image description here

I need help figuring this out to make it work

Godot version Godot 4
in Engine by (12 points)

1 Answer

0 votes

From the Node class docs if get_node can't find your node. It will return null. That seems to be what's happening to you.

So a couple things you can check.
1. Is "Camera" the correct name of your node when you run the game?
2. Is Camera a Node under the Player.tscn scene?

If 1 is true and 2 is false. You mignt need to run:

 get_tree().get_root().get_node("Camera")

to make sure you are searching through the entire SceneTree instead of just your Player node.

Hopefully this helps. Another thing you can try is caching the reference to Camera so that you are not searching the tree every frame:

var camera: Node
func _ready() -> void:
    camera = get_tree().get_root().get_node("Camera")

Then use camera.rotate_x on your input event

by (180 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.