- Home /
LockOn GUI Question
Hello,
I am hoping I can get some guidance on how to better setup this system I am making. Right now I have a "lock on" system that basically uses a Ray and timer to see if a target is locked on, then it activates GUI elements. It is "working", but the GUI is a little wonky, the best I could do is manually line up the GUI elements in 2d mode and play around with it. It stays with the target when it moves around, which I want, but as it moves around in 3D space it gets a little wonky.
I feel like I should be using a 2nd camera somehow and WorldToViewportPoint elements, but i'm not really sure if that's what I need or the best way to do it. If anyone can point me in the right direction that would be helpful.
EDIT: I have also tried adding a reticle as IMAGE and trying the worldviewpoint but have not been able to get that to work either:
myReticle.transform.position = myCam.WorldToViewportPoint(hit.point);
Here is an example with a cube as an enemy:
https://gyazo.com/887c1e122a0282b513ed9834fda4e6a8
I am basically trying to get something like this, not really as fancy for now:
Answer by JonPQ · Sep 04, 2019 at 09:27 PM
the step you are missing is you need to do 2 transforms... not just one. You have your world camera, and your 2D/Gui camera, Take your node abouve the object to be targetted, and do world to view point on this, using the world camera. now using the 2d Gui camera, do same in reverse, viewtoWorld. to find the position at which to put your Lock on Gui object. (rendered by the the Ui camera, by using layer setting)
So I just setup a test scene with one camera and a simple script on the "enemy", ins$$anonymous$$d of where I had it on my Player, so maybe I am just overthinking it and need to get some functions working together in my main scene.
This looks closer to something I was looking for, does this look like a correct way to do it?
yes there are generally 2 ways to do this..... 1) all with your one 3d camera, jsut attach the lock on object as a child of your targeted object ( say enemy soldier) the down side is it will sort with other 3d objects, and get bigger and smaller with range from camera. IF you like it getting smaller with range... you could just add a second camera, also 3d, which is a child of your main camera. with camera depth set to be higher than the main camera so everythign this camera draws is last.... then put your target reticle in the layer drawn by this camera (make sure that camera draws nothing else) or 2) use a second UI overlay or world space camera... and use the 2 step world to view, then view to world from one camera to the other. and position your reticle there. Advantages and disabfantages to both methods... depending on what you want.
Answer by millej23 · Sep 05, 2019 at 11:41 AM
Thanks for the reply, I think I understand. So I should be adding a second camera for GUI elements only then and basically get the transform again using the second cam? If you know of a good tutorial too that would be helpful, thanks!
Your answer
Follow this Question
Related Questions
Scene Is Missing A Full Screen Camera? 2 Answers
UI Minimap 0 Answers
How can I display text so that it can be see on the Vive Headset? 0 Answers
PauseMenu - FPS Camera still moves when in PauseMenu 2 Answers