I have a large level. I want to move the camera when the player hits a border but I don't want the camera to move with the player.

Example: The game view is 1366, 768
If the player touches the full right of the view the camera then moves 1366 pixels to the right and vice versa for each part of the current view. I don't want the camera to follow the player just to move by it's full width or height when my player hits the border.

  • Oh! Is it you just don't know how to access the camera in the hierarchy? In that case groups are a perfect way of doing this, they work very similar to tags in other engines.

    @onready var playerCameraGroup = get_tree().get_nodes_in_group("PlayerCamera")
    @onready var playerCamera = playerCameraGroup[0]

    This is how I use groups quite often to access something that isn't a child which can get tricky, worth pointing out as well that in Godot you can use multiple groups on the same node, think of groups as a list, which is why you have to assign an individual variable a node from that list first before being able to use it.

Place area colliders at the edge of the map then have the camera respond appropriately to the signals once entered, that should act as a good enough boundary if I'm understand what you want to do.

  • Amon replied to this.

    Lethn I've done that but I could use with a gdscript way of grabbing the camera and shifting the view, or maybe just grabbing the current camera via script which will allow me to access its position data.

    Oh! Is it you just don't know how to access the camera in the hierarchy? In that case groups are a perfect way of doing this, they work very similar to tags in other engines.

    @onready var playerCameraGroup = get_tree().get_nodes_in_group("PlayerCamera")
    @onready var playerCamera = playerCameraGroup[0]

    This is how I use groups quite often to access something that isn't a child which can get tricky, worth pointing out as well that in Godot you can use multiple groups on the same node, think of groups as a list, which is why you have to assign an individual variable a node from that list first before being able to use it.

    • Amon replied to this.

      Lethn I'm assuming that this grabs the default camera in the main scene where my character is? Do I understand it correctly that get_tree().get_nodes_in_group("PlayerCamera") will grab the first camera that is present in the scene tree group?

      Yes, that's right, you then use playerCamera.global_transform.whatever as a pseudo example to grab what data you need, as you're understanding you can grab the next node in the list by changing the index. In your defence, the documentation doesn't necessarily do a good job of explaining this and the new raycast system, I think there needs to be some more real world examples posted there to help people understand because groups can be very powerful when used correctly.

      • Amon replied to this.

        Lethn Perfect. Thank you for helping me. And yes, I did try the documentation first but it was very vague and didn't help at all.