Author Topic: Having 2d Sprites In A 3d World Space?  (Read 5044 times)

edisonfloyd

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Having 2d Sprites In A 3d World Space?
« on: August 24, 2013, 07:52:32 PM »
Hi there!

I'm trying to put some 2d sprites into a 3d world space similar to what you can see in this screen shot of Ragnorok Online 2.



The main thing to notice here is all the 2d sprites that are linked to a 3d world space: the enemy health bar that rests over their head, the npc's quest marker, and the other npc has a song icon. I'd like to recreate this effect and was wondering if NGUI had any built in functionality to do it.

Currently I have a 3d (advanced) camera UI setup which only draws the sprites I want it to and exactly matches my main 3d camera which draws the rest of the world. Unfortunately the UI camera draws sprites as though they were planes rather than 2d images (it's drawing them in 3d space essentially) which results in the sprites not showing up correctly. If there's a better way to go about the setup to achieve the result I'd be happy to hear it!

Thank you very much for reading and any help.

EDIT:
The solution I've found that works alright is to set the sprite's transform.up to the camera's transform.up. This makes is so that the sprite is always "facing" the same direction as the camera and fov doesn't seem to play into it very much so I simply ignored that.

If there's a better solution I'd be happy to hear it but this works alright for my purposes.
« Last Edit: August 24, 2013, 11:07:00 PM by edisonfloyd »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having 2d Sprites In A 3d World Space?
« Reply #1 on: August 25, 2013, 02:21:31 PM »
Just a note -- the image you posted doesn't show up. But yes, what you're doing is fine.

Kiliaan

  • Guest
Re: Having 2d Sprites In A 3d World Space?
« Reply #2 on: October 28, 2013, 06:18:09 PM »
I am trying to do something similar, rather than simply an indicator as in the original post I would like to have a small NGUI menu placed at the location of the object  that is selected, how would I accomplish this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having 2d Sprites In A 3d World Space?
« Reply #3 on: October 29, 2013, 12:35:43 AM »
Check the FAQ.

Kiliaan

  • Guest
Re: Having 2d Sprites In A 3d World Space?
« Reply #4 on: October 30, 2013, 07:22:31 PM »
I didn't find anything related in the FAQ but I did go through all your stuff and assume you were pointing me to the NGUI Hud Text information?  I didn't want to spend extra on that but I did find a very simple way to translate from 3d main camera to 2d NGUI camera, could be useful if you don't have NGUI Hud Text and want to accomplish something similar.

  Vector3 myObjectPos = Camera.main.WorldToScreenPoint(this.transform.position);
  Vector3  myMenuPos= GameObject.FindWithTag("NGUICam").camera.ScreenToWorldPoint(myObjectPos);
  myNGUImenu.transform.position = myMenuPos;

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having 2d Sprites In A 3d World Space?
« Reply #5 on: November 01, 2013, 08:34:49 AM »
Sorry I actually meant the Useful Stuff sticky post, not the FAQ. Mistyped. The second link there links to a post on how to make health bars that follow a 3D object.