Random error when trying to keep the camera's y axis still

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ahlyia

Im trying to make a sort of 3rd person thing and i want the y axis of the camera to be stationary so only the x and z can move, but im having a weird error.

extends Camera3D



func _ready():
    pass # Replace with function body.



func _process(delta):
    self.global_position = Vector3(self.global_position.x, clamp(self.global_position.y, 0, 0.605), self.global_position.z)

btw the error is

Invalid get index ‘global_position’ (on base: ‘Camera3D ()’)

Hmmm… I don’t see anything obviously wrong there. Is that the complete error? It looks a little strange to me. For example, if I intentionally put a typo in the global_position property name to generate a similar error (because the actual property works fine here), I get the following error:

Invalid set index 'global_positionz' (on base: 'Camera3D') with value of type 'Vector3'.

While it’s similar to your error, I’d expect it to match exactly - unless you haven’t pasted the compete error?

Really, grasping at straws here as the code looks OK to me on the surface…

jgodfrey | 2023-01-19 03:09

Ah, wait. I see the error difference. I broke the set side of the expression. In your case, it’s the get side. So, my replicated error looks like this now (again, with an intentionally broken property name)

Invalid get index 'global_positionz' (on base: 'Camera3D').

jgodfrey | 2023-01-19 03:13

Just set up a test scene to verify. That code works perfectly fine here (using Godot 4, beta 12).

jgodfrey | 2023-01-19 03:19

hmm, thats odd, im using Godot 4, Alpha 9 right now.

Ahlyia | 2023-01-19 11:58

I found out why, i was using 4.0 version 9 and for some reason it only works on version 12

Ahlyia | 2023-01-19 12:03