Rotational windows around a central point, but opposite another point. (clear as mud title)

Howdy all! Been awhile since i last asked a question.

I have a system I’ve designed for popup windows, things like Inventory screens, tooltips, etc, that when the window is displayed, it’s location changes according to the quadrant of the screen it’s in. For instance, if it appears in the lower left quadrant of the screen It then sets the pivot so that the window will be to the top right of the item. It’s working great, however, i want to expand on this…

I want to take something like a treasure chest, and depending on where the chest is positioned in relationship to the player, the window rotates to the other side of the chest (but also takes into consideration that quadrant rotation so a player couldn’t “Push” the window off the screen). I’d love to do something like a 360 arc a specific distance away from the chest, relationally on the opposite side of the chest from the player.

I have it working in a hemispheric way on the X axis. If the player opens the chest, the inventory pops up to the left, and via the update function, if the player moves to the left of the chest where the window is open, the window will pop over to the right. However, it’s very jarring if and when it snaps back and forth. Say in the case when a player is standing close to the center of the X postion of the chest and wiggles their character back and forth.

Here’s a code snip from the window’s update script to show what i’ve got so far. I could probably hack this out given some time, but then i started thinking about what performance impact this may have on my game as well. I’m thinking this is probably expensive doing a find in the update?

    private void Update() {
        if (isActiveAndEnabled){
            offset = (mainCamera.WorldToScreenPoint(MyChestTransform.position).x > (Screen.width / 2f) ? 150f : -150f);
            transform.Find("Slots").position = new Vector2(mainCamera.WorldToScreenPoint(MyChestTransform.position).x + offset, mainCamera.WorldToScreenPoint(MyChestTransform.position).y);
        }
    }

I should probably clarify a touch, in the code snipped “MyChestTransform.position” is the location of the chest. “Slots”.position is the location of the popup window.

i think i’m probably looking for an answer somewhere in the rotate or lookat public method. I’m just failing with how to get the player’s location to impact the rotational point of the window.

I have this working where it positions the contents windows for the chest on the corner furthest away from the player. It’s actually using the distance from the center of the screen and not the player. I can’t really figure out how to do this in a circle arc like motion based off the distance from the chest.transform.position to the center of the screen, I’d probably have to do something with angles and sin/cos, but i’m really not getting it tonight.

I’ve just about solved this, but i’ll move the question i have over to the scripting area, as i think this location is not the best place to ask the question. Thanks!

This is the 2D forum. It is not for posts about general game logic or problems or general scripting. That’ll be the scripting forum.

I’ll move your post for you.