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);
}
}