x


WorldToViewportPoint/ScreenPoint creates two points

Whenever I use WorldToViewportPoint/WorldToScreenPoint to place a GUITexture/Texture on a GameObject it always gives two points. One point is on the the GameObject and the other is on the mirror location of the GameObject across the Z-axis(Example (1,1,1)(1,1,-1)). So when the camera turns around the mirrored-Texture is floating over empty space. This can be simply solved by adding if(Z-axis>0){}, but in this situation it won't. I'm tagging an enemy and clamping the position of the texture to the screen. So when the Z-axis is negative the texture becomes static until the Z-axis becomes positive again. Which isn't exactly helpful when a player is trying to find the enemy. So my question is, is there anyway to fix the two point issue?

P.S. - I've also tried Mathf.Abs(Z-axis), but that does not fix the issue.

more ▼

asked Jan 18 '11 at 05:55 PM

Josh Wilson gravatar image

Josh Wilson
18 1 2 2

If we could see your code, we might be able to help you further. I've never had what you describe happen, so I don't think it is a feature of WorldToScreenPoint...

Jan 18 '11 at 10:41 PM The_r0nin
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

http://www.unifycommunity.com/wiki/index.php?title=ObjectLabel

      var relativePosition = camTransform.InverseTransformPoint(target.position);
    relativePosition.z = Mathf.Max(relativePosition.z, 1.0);
    thisTransform.position = cam.WorldToViewportPoint(camTransform.TransformPoint(relativePosition + offset));

This turned out to be the answer. If you take the GameObject's position straight from the world it will give two on camera points(front,behind). In-versing the GameObject's position and then applying a reference to the camera with TransformPoint filters out the the phantom point.

more ▼

answered Jan 19 '11 at 05:29 AM

Josh Wilson gravatar image

Josh Wilson
18 1 2 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x25

asked: Jan 18 '11 at 05:55 PM

Seen: 1418 times

Last Updated: Jan 18 '11 at 05:55 PM