Rotating the camera while maintaining a HUD
patrickbeardmore
Member Posts: 11
My game involves a scene where the viewer is in a helicopter, looking down, while the scene rotates and moves below. I am trying to use interpolate to rotate the camera, which is working well, but I cannot work out how to make the HUD (head up display) overlay layer stay still.
Does anyone have any tested solutions. An example file would be ideal. Regards, Patrick
Does anyone have any tested solutions. An example file would be ideal. Regards, Patrick
Best Answer
-
UtopianGames Posts: 5,692When you rotate the camera it doesn't change the positions of the HUD buttons like rotate left rotate right etc etc even though it looks like it does so there's no need to move them at all.
Here's a quick video of an older project with rotation of the camera and a stationary HUD.
Hope it helps.
Darren.
Answers
"-(scene.camera.rotation)"
But that's only half of the battle
keeping it in place is the hard part, that I have still not figured out a way of doing.
I made one single HUD graphic which was transparent, the size of my entire screen and this had all of the HUD elements drawn on it. Then by using contrain to -scene.camera rotation, the whole HUD graphic rotates from the centre, keeping everything in place as it rotates.
Obviously you now can't use this graphic to detect touches, as the whole screen would register a touch, so I added some invisible buttons above the HUD graphic to detect touches.
I'm lucky because in my game the camera only rotates when the left or right button is pressed, so I don't need to constrain the invisible buttons to keep them in place, I simply have a rule saying that during camera rotation the buttons can't be pressed, and once camera rotation is complete I simply move the invisible buttons to a pre set coordinate that I know is in line with my rotated HUD graphic.
Depending on the rotation in your game this might not be a complete solution for you but it might help!
If you wanted to do something about layers, you could go to your scene, click on scene attributes, go to layers and create a new layer. Put all the buttons and things you want on the HUD in the new layer and unclick scrollable. This will make the HUD always stay in the same spot.
In the long-term, it would be handy to have a check box next to "scrollable" for "rotatable" in the layers panel, to avoid this problem.
If I understand it, the image and the button registration becomes misaligned, but this can be used to make the HUD work anyway.
@patrickbeardmore Yeah there seems to be a weird situation going on with the buttons - even though they graphically appear to move, their touch detection still seems to stay in the original location. It must be a GS bug that's actually working in our favour for this situation.
To clarify my earlier explanation - in my particular game the screen rotates in four directions - every time you press left or right you rotate by 90 degrees. As well as this the hud position never moves from 0,0, it only rotates. Because of this I worked out (with some manual placement and testing) that when rotation=90 degrees button1 must be at a certain position, so I had a rule saying when camera.rotation=90 set button position to (relevant coordinates), then if camera.rotation=180 set button.position to (relevant coordinates), etc. Because the button isn't visible you never see it moving to it's new position.
However seeing as the buttons seem to always detect touch at the same place I might not actually need these rules anymore!