How do I move the HUD when player collects stuff/presses a key?

Hello, so you know those games where the HUD is offscreen but shows up on screen when you collect stuff? Like let’s say you collect a coin, the coin icon and number would show up and go back offscreen if you don’t get another coin for a few seconds, and the life icon shows up when you get an extra life, I also want when you a press a button it makes the whole HUD (Coins + Lives) show up.
Here’s an image to demonstrate.


I tried to do this with tweens, but always something would go wrong, either it would keep moving left/right the more you collect/press the key, I tried putting various conditions like X position of LifeHUD/CoinHUD, opacity, tween playing and such and all of them break something after a while and have it not work, what’s the best way to do this?

Put the HUD on a separate layer, or layers if you want them to move in different directions at the same time. Them move the camera of that layer in the opposite direction to how you want the objects to move.

1 Like

I’m trying it and so far it seems to work, although is there a way to know the X and Y of the layer? It’s annoying trying to get it by guessing

What do you mean by the X & Y of the layer? Or do you mean the camera?

Oh sorry I meant the camera yeah

The camera’s position is in the game world/scene. On screen however, it’s always in the middle. My rule of thumb is to move the camera a screen width or height away. If you tween it, you can start fast and stop smoothly.

To visualise it better, take a mobile phone and put it over a larger picture. The larger picture is the HUD and the phone is the HUD layer camera.

1 Like

First of all I suggest you to maintain the HUD on the screen without any effect.
Does it works moving the player on the screen ?

Thank you! It was a hassle to get the exact positions, but in the end it worked, it’s much better tweening the camera than the X/Y positions of the HUD elements themselves

1 Like