Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add margin for nodes in follow_targets array. #385

Open
Jack-023 opened this issue Sep 13, 2024 · 2 comments
Open

Add margin for nodes in follow_targets array. #385

Jack-023 opened this issue Sep 13, 2024 · 2 comments

Comments

@Jack-023
Copy link
Contributor

Project Type

2D

Feature Description

Add a margin setting (at least for one "primary" element) for nodes in the follow_targets group when using the group follow mode.
The margin would ensure that the area described by the margins would always be inside the viewport.

Use Cases

I am currently working on a top-down shooter style game. I have set up a camera to follow the player, while dynamically being offset to follow the mouse cursor. This is because you want to be able to see further in the direction that you are aiming, rather than having the camera centered on the player. The way I am achieving this is by having an invisible Node2D that follows the mouse cursor and adding it to a follow group with the player. I want the camera to stay at a fixed zoom, and keep both nodes in the frame simply by moving. This should work fine because the cursor is locked to the window so it doesn't have any way to go too far from the player.

I also want some minimum distance between the player and the edge viewport. Because the group follow mode calculates its target based on the global position of the target nodes, it will only ensure that the center of the nodes are in the frame. eg
screenshot

Currently I am able to get around this by adding four Node2D objects as children of the player at relative positions of (-40,0), (40,0), (0, 40), (0, -40) and adding them to the target group. Result here:
screenshot2

This is pretty clunky to set up though and tweaking the margins is tedious as I need to individually go into all 4 nodes. It would be nice if there was a margin parameter that could create and add these nodes to the group automatically.

(Optional) Proposed Solution

The solution for my use-case is pretty straightforward and I would be happy to implement it but I am not sure how to expose the values in a way that feels clean. While writing this up I realised that it might actually make the most sense for this to be a completely separate follow type. The reason this works in my specific use case is because the cursor is indirectly tied to the main target of the camera. If a second target was added that was completely independent then there is no way to capture both targets without changing the zoom level. Having said that, this setup feels generic enough that there is probably value in adding it as a new type.

@ramokz
Copy link
Owner

ramokz commented Sep 13, 2024

If I understand it correctly, and to summarize, you're looking for a way to apply a margin to individual targets within a follow group? Kinda like if you could apply a Vector4 margin to each Node2D array target?

@Jack-023
Copy link
Contributor Author

Essentially what I am going for is the inverse of the "Framed" follow mode. Instead of a deadzone that moves the camera when the node hits the boundary, you offset the camera and it can't move past the boundary around the followed node.

When I was thinking about generalizing this I realized that generalizing it to apply to multiple nodes in the array doesn't really work (since I am using a fixed zoom) so while I was able to create the effect using follow groups it might make more sense to support it as a different mode if creating a simpler interface for this style of camera.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants