Author Topic: how to get exact position of a sprite or a button in the "main camera"  (Read 11058 times)

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Hi,


I would like to send some particles from my player to a NGUI Sprite or buttons.


But I can't get the good position of this sprite in the "real world"  where is my character.


I have two cameras : the NGUI camera and the main camera who is fall awing my character.


Thank you.

Bets regards,

AB

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #1 on: September 10, 2014, 01:31:13 AM »
Math. Have a look inside NGUIMath.OverlayPosition. It does all this math inside.

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #2 on: September 10, 2014, 01:42:45 AM »
HI,

thank you for your quick answer.

Is there a Playmaker action for this ? I didn't  find it .. :'(

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #3 on: September 10, 2014, 01:56:10 AM »
Or just an exemple if you have a sec thank you very very much !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #4 on: September 11, 2014, 01:03:45 AM »
You'd need to ask that on the Playmaker support forum. NGUI doesn't have any Playmaker actions inside.

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #5 on: September 11, 2014, 01:10:52 AM »
Hi,

Thanks for your answer.

Don't worry with Playmaker, I will write myself my Playmaker action.

But in C#, do you have an exemple for me please ? I did search on the net ... I found nothing.



Thank you very much in advance !


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #6 on: September 11, 2014, 01:48:09 AM »
I mentioned where you can find the code... NGUIMath.OverlayPosition function. Just look inside that function, and there is all the math inside, and an example in itself.

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #7 on: September 11, 2014, 01:55:29 AM »
Thank you.

Don't think I don't do any effort.

If take a long time yesterday to try and try again,  but it didn't work.

Sorry.


There is 2 functions :


static void NGUIMath.OverlayPosition   (   this Transform    trans,
Vector3    worldPos,
Camera    worldCam,
Camera    myCam
)   


AND



static void NGUIMath.OverlayPosition   (   this Transform    trans,
Vector3    worldPos,
Camera    worldCam
)   

with :

Parameters
worldPos   World position, visible by the worldCam
worldCam   Camera that is able to see the worldPos
myCam   Camera that is able to see the transform this function is called on



But what is "trans" ? Is it required ?

This is a void function, so the "worldPos" variable is the coordinate of my Widget from Ngui (so from the Ngui camera) in my main camera ?


Thank you in advance. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #8 on: September 12, 2014, 03:44:14 AM »
It's an extension method. "trans" is what you use to access it.
  1. widgetTransform.OverlayPosition(some3DPosition, Camera.mainCamera);

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #9 on: September 12, 2014, 03:45:52 AM »
Thanks I try it immediately !  8)

ababab5

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #10 on: September 12, 2014, 04:26:25 AM »
To understand, because it's unfortunately not the case :

GameObject theObjectIWantToPositioningInMyMainCamera;
Camera myMainCamera;
Vector3 thePositionOfTheNGUIWidgetInTheNGUICamera;

Do I call this :

theObjectIWantToPositioningInMyMainCamera.transform.OverlayPosition ( thePositionOfTheNGUIWidgetInTheNGUICamera , myMainCamera);

?

Thanks again

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to get exact position of a sprite or a button in the "main camera"
« Reply #11 on: September 13, 2014, 03:14:48 AM »
No. The camera passed to the function needs to be the camera that draws the object passed to that function.

Your original question was:
Quote
I would like to send some particles from my player to a NGUI Sprite or buttons.
...and yet you seem to be now trying to do the opposite and position your 3D object using your UI element? Why? UI elements are in 2D. Game gbjects are in 3D. 3D objects have 1 extra dimension, so you can't go from 2D to 3D easily, but you can go from 3D to 2D.

The correct way of positioning your widget on top of your 3D object is:
  1. widget.transform.OverlayPosition(your3DObject.transform.position, Camera.mainCamera);