Invalid get index 'rotation' (on base:'null instance') im coding a camera movement

Godot Version

Question

so im trying to code a camera where it moves with your mouse under this code: if(event is InputEventMouseMotion) under that is rotation.y -= event.relative.x / 1000 * sensitivity which is 3, under that would be $camera3d.rotation.x -= event.relative.y / 1000 * sensitivity under that would be rotation.x = clamp(rotation.x, PI/-2, PI/2) if you find a solution please tell me or any other substitution for this that would help as well as any other tips.

Hey uoppou,

You probably want to check if $camera3d is in your SceneTree. It might be spelled differently or using the wrong node path.

Lmk what you find.

2 Likes

it worked i guess there was a typo in my stuff but it worked when i re named it. thank you. could you help me with another thing, the mouse still drags out of the screen i was hoping you had a way to kinda capture the mouse in the game so the look feature actually works?

You will want to place this line of code in the ready() or init() of one of your top-level Nodes. I generally, put it with my player script.

Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

See Input — Godot Engine (stable) documentation in English for more information on how capturing the mouse works.

Also, KidsCanCode wrote an article about it for Godot 3 that mostly still applies to Godot 4.
https://kidscancode.org/godot_recipes/3.x/input/mouse_capture/index.html

1 Like

yeah this works. thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.