• Godot Help
  • How do I freeze the X and the Z on my camera?

I've been trying to make the camera only follow the Y axis of my character and I do not know how to solve this.

Not sure about your setup, maybe that way:

camera.global_position.y = player.global_position.y

    trizZzle
    That only makes it get to the same Y axis. i tried removing the camera from the player scripting but this engine does not like node communication it seems. Too bad!

      AMI That only makes it get to the same Y axis. i tried removing the camera from the player scripting but this engine does not like node communication it seems. Too bad!

      I don't understand what you mean.
      If you show us your code and your scene setup it is easier to understand and help.

      • AMI replied to this.
        2 months later

        trizZzle I ended up solving this problem after extreme emotional turmoil and nearly breaking up with my fiance over the stress

        xtends Camera3D

        var initial_position = Vector3.ZERO # Store the initial position of the camera

        func _ready():

        Store the initial position of the camera

        initial_position = global_transform.origin

        func _process(delta):

        Get current camera position

        var camera_pos = global_transform.origin

        # Freeze X and Z positions relative to initial position
        camera_pos.x = initial_position.x  # Set X position to initial X position
        camera_pos.z = initial_position.z  # Set Z position to initial Z position
        
        # Update camera position
        global_transform.origin = camera_pos

        You can also alter this stuff in order to freeze the axis directions as you please