Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: judy3t on August 10, 2012, 12:11:23 PM

Title: Health bars with first person camera
Post by: judy3t on August 10, 2012, 12:11:23 PM
The health bar example works great when I use a the default main camera.  However, with all the camera settings exactly the same between the camera on the FPS character controller and the Main Camera the unit HUD does not show up with the FPS character controller prefab. 

The only difference I can see between the FPS camera and the Main Camera is the depth.  I tried playing with the depth but that didn't fix it.  Oddly, when I replaced the camera from the FPS prefab with the default main camera that works, the FPS camera started working.  But looking at the two cameras, setting the layers and the culling masks identically why would one work and the other not?   Is there something I'm just not understanding about the cameras? 

Has anyone gotten this to work with the FPS character controller prefab?  What did you change?

Thanks,
Judy
Title: Re: Health bars with first person camera
Post by: DoctorWhy on August 10, 2012, 12:57:45 PM
I may not be of much help, but there are two things I noticed about using Cameras to show a HUD.  1)You should have a separate camera for a HUD that is always drawn before the other Camera (have a greater depth.  So if the FPS camera has a depth of 10, you want the HUD camera to have a depth of 11).  2)The new HUD camera should be in Orthogonal view, so there is not depth to the HUD (unless that is the effect that you want).

EDIT: Oh, and make sure the orthogonal size is set to something small enough.  I think the default is 100.  I have mine set to 4.

I am not sure if that will help, but there is some of my input.
Title: Re: Health bars with first person camera
Post by: judy3t on August 10, 2012, 02:08:28 PM
Curiouser and curiouser...

It seems that the UICamera returns a different value from ViewportToWorldPoint() when processing the exact same vector3 with the exact same target position depending on whether the camera is the default camera that is in the scene when the scene is originally created or if it is spawned in camera created later, even when both of those main cameras have exactly the same settings.   

Since I cannot debug into ViewportToWorldPoint() I am going to declare myself stymied and wait to find out if anyone has used another camera and gotten this to work, preferably with the FPS prefab, but I'm not picky.  I can't even spawn in a new Main Camera.  The ONLY camera that works is the default main camera when I create a scene. 

*boggle*



Title: Re: Health bars with first person camera
Post by: ArenMook on August 10, 2012, 04:45:21 PM
@DoctorWhy: Orthographic size should remain at 1 for NGUI. The HUD should also be drawn after the game camera, not before. Otherwise game camera will erase the HUD.

@judy3t: What is this FPS character controller you speak of?
Title: Re: Health bars with first person camera
Post by: judy3t on August 10, 2012, 06:56:31 PM
When you create a new Unity project, one of the standard packages is "Character Controllers".  In this package are two character controllers, First Person Character Controller and Third Person Character Controller.  The first person character controller prefab has a main camera attached.

I have found a workaround that works in my test environment.  I created a new prefab for the first person controller without the camera, leave the main camera in the scene and then, after instantiating the first person controller, attach the main camera to it.  Unfortunately, this doesn't work in my game environment (yet).   

I'd love to know if you get this problem as well.  It's one of those "makes no sense" bugs   
Title: Re: Health bars with first person camera
Post by: judy3t on August 15, 2012, 05:03:13 PM
Well it seems that there is just no way to make the healthbar tutorial work when using a First Person Controller. This makes me sad. 
Title: Re: Health bars with first person camera
Post by: ArenMook on August 15, 2012, 09:04:30 PM
You say that the controller already has a main camera... and then you say that you attach a main camera to it. Which one is it then? I assume both are tagged as "Main Camera", which means it's not clear which one would come up when you do Camera.main.
Title: Re: Health bars with first person camera
Post by: judy3t on August 16, 2012, 05:40:58 PM
I'll try and explain the systematic way I went about isolating the problem.

First I created the prefab for just a simple label and added UnitHUD to it.  Then I created a plane and put a cube on it and attached addUnitHUD to the cube.  I ran this alone with the main camera as created when creating a scene.  IT is labelled as "main camera" and its culling is "everything" and it is in the default layer.   The camera for the UI is not labelled, but has its culling as "HUD" and is in the HUD layer. Worked great.

Then I removed the main camera and put in the first person controller.  The first person controller prefab has a main camera attached to it.  It is labelled as "main camera", it's culling is "everything" and it is in the default layer.  The HUD pieces remained exactly the same.  Now the box label does not show up.

Then I wanted to go back to the main camera so I removed the first person controller and created a camera from the Assets->Create->Camera menu.  I renamed it main camera, had its culling set to everything and had it run in the default settings as main camera.   This did not return me to the state at the start of the scene.  The box label still did not show up.

Create new scene, repeat and I was only able to get it to work with the camera that is set as the default in the scene.  Nothing I could do with camera controls could change that (that's the part I'm stumped by).  At random times I would get into a state where I couldn't see the world, only gray and the label from the NGUI camera. 

So if you just follow the first steps, create a label you can see with main camera, swap out the main camera and swap in the first person character controller, you should see the same problem I had.

For a work around I tried having the main camera in the scene and spawning in a first person controller without a camera, then attaching the main camera to the character controller.  I was then able to see the label on the box, but I could no longer use mouselook to control my camera in all directions.  It would not turn from left to right. 

That's when I gave up.  I have learned to do what I need here with the native Unity GUI commands.  But it means the NGUI won't be usable for a HUD for me as my entire game is first person controller played and I simply could NOT get the NGUI camera to cooperate with the first person controller camera. 
Title: Re: Health bars with first person camera
Post by: ArenMook on August 16, 2012, 07:07:04 PM
Are you sure your first person controller's camera has the depth of 0?
Title: Re: Health bars with first person camera
Post by: judy3t on August 22, 2012, 11:43:44 AM
It defaults to 0 and I've never changed it.