playMaker

Author Topic: "Parenting" objects to edge of screen[SOLVED]  (Read 4234 times)

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
"Parenting" objects to edge of screen[SOLVED]
« on: November 03, 2013, 10:15:14 PM »
For my user interface, I'm using 3D objects which are parented to the camera. This works pretty well and I'm pleased with the appearance of it. I love how the UI changes colors based on the scene lighting/camera angle.

However, I'm having a hard time figuring out a way to keep the elements at the edge of the screen as it changes sizes. I understand there's a "get screen width/height" action, but I'm not sure how to properly convert that information [pixels] to translate an object to rest at a certain position [Unity units].

I'm an HTML/CSS guy, so in my head I just want there to be a way to say "always make 'Object1' 20 pixels to the right of the screen edge", but it's not that simple haha.

Any ideas?
« Last Edit: November 05, 2013, 08:36:05 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "Parenting" objects to edge of screen
« Reply #1 on: November 04, 2013, 12:48:25 AM »
Hi,

Are you takinf about UI elements here or actual 3d objects?

For ui elements, you can use GUI texture, set the position to anchor in a screen corner and use the pixel inset offset to precisly be at 20 pixel from a screen side.

if you are using ngui or other, then they have "anchoring" helpers, doing very much like the GUi Texture above,

If you are using a 3d object for real, then in ngui you can attach it to the anchor, but without any framework then I would use the MouseDrag action:

http://hutonggames.com/playmakerforum/index.php?topic=272.msg1087#msg1087

It's call mouse, but you can inject any screen point and so you can precisly know a position in the 3d world to be exactyl 20 pixel of your screen border.

bye,

 Jean

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: "Parenting" objects to edge of screen
« Reply #2 on: November 04, 2013, 01:59:46 AM »
Jean,

Thanks for giving me advice and pointing me in the right direction! To answer your question, I'm using real 3D objects (for example, I have a row of 3D hearts which create the health bar). No actual GUI scripts or Playmaker GUI actions, just 3D shapes parented to the camera, which appear/disappear based on in-game events.

I'd love to try attaching my existing setup to a gui anchor before I attempt the second option. Do you have any recommendations on how to setup a gui anchor?

Thanks again for the guidance.

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: "Parenting" objects to edge of screen
« Reply #3 on: November 04, 2013, 02:08:19 AM »
I just found this script, which is apparently a method of doing what I need:

var v3Pos = Vector3(0.0, 1.0, 0.25);
transform.position = gui.camera.ViewportToWorldPoint(v3Pos);

There is a function called ViewportToWorldPoint which seems to be what I need, but sadly I'm not very good at UnityScript at all, so I'm not sure how to implement this. I wonder if there is a similar function in PlayMaker that I might not be aware of?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: "Parenting" objects to edge of screen
« Reply #4 on: November 04, 2013, 05:01:38 AM »
Hi,

 Actually, if you want to use pixels, then you need the action "Screen to World Point"

https://hutonggames.fogbugz.com/default.asp?W570

Can you double check with the unity doc which one you need?

http://hutonggames.com/playmakerforum/index.php?topic=5109.msg24240#msg24240



colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: "Parenting" objects to edge of screen
« Reply #5 on: November 05, 2013, 03:47:16 AM »
Jean,

Thanks for giving me advice and pointing me in the right direction! To answer your question, I'm using real 3D objects (for example, I have a row of 3D hearts which create the health bar). No actual GUI scripts or Playmaker GUI actions, just 3D shapes parented to the camera, which appear/disappear based on in-game events.

I'd love to try attaching my existing setup to a gui anchor before I attempt the second option. Do you have any recommendations on how to setup a gui anchor?

Thanks again for the guidance.

Hi could you possibly share more information on

I'm using real 3D objects (for example, I have a row of 3D hearts which create the health bar). No actual GUI scripts or Playmaker GUI actions, just 3D shapes parented to the camera, which appear/disappear based on in-game events.

I am having trouble setting up this concept.

When I loose a single life with my efforts all of the lives are effected as they all meet the in game events.

However I am destroying mine.

maybe you could help me out?

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: "Parenting" objects to edge of screen
« Reply #6 on: November 05, 2013, 08:23:19 AM »
I was able to work it out myself.

https://dl.dropboxusercontent.com/u/150707256/playmaker/new%20build.html

players lives now added, with thanks to your idea.