GUITexture stay put when camera moves...

Hiya,

I have a guiTexture that becomes visible when selecting a GO in the scene. What I am looking to do is have that guiTexture maintain it’s world position and ignore the movement of the camera. For example, I click on the GO and the guiTexture positions itself a bit offset where I click. When I move the camera via a FPS script the guiTexture stays in that position within the camera viewPort versus staying where “in the world” I clicked. The code I am using looks like this:

worldPos = Camera.main.ScreenToWorldPoint(Vector2(Input.mousePosition.x, Input.mousePosition.y - 64));
	
gameObject.transform.position = Camera.main.WorldToViewportPoint(worldPos);

I have tried several different things in the Update function to try and maintain it’s position but none seem to work as expected. Anyone have some insight?

Thanks!

– Clint

rather than Gui, perhaps a GO? I think the line renderer does a kind of “single Billboard” type thing, that wouldnt move round…
AC

HHHMMM,

Thanks Targos! I looked at the lineRenderer a bit and it doesn’t seem to give me the control and ease that the GUITextures do. I want the elements to be rendered above everything else (closest to the camera) but just don’t want the elements to move with the camera. In other words where I place the elements upon interaction is the position I want them to stay at (based on the position) when moving the camera, currently they keep the viewport.

Any other ideas?

Thanks!

– Clint

pretty sure it stays in the viewport because it’s a guitexture. sounds like you probably just want to instantiate a camera facing billboard (a 2 tri plane) as a game object.

Hiya,

After some discussions with Jo and better explaining my problem (hate it when I do that) it turned out I essentially was super far off but needed the InverseTransformPoint and TransformPoint functions and a LateUpdate versus a regular Update. So that my code looks like this:

private var visible : boolean;

private var target : Transform;
private var localPos : Vector3;

function show ( newTarget : Transform, newWorldPos : Vector3 ) {
	
     localPos = newTarget.InverseTransformPoint(newWorldPos);
     target = newTarget;
     gameObject.SetActiveRecursively(true);
	
     // Set Visible Flag
     visible = true;
	
}


function LateUpdate () {

     if ( visible ) {
          var worldPoint = target.TransformPoint(localPos);
          var vect : Vector3 = Camera.main.WorldToViewportPoint( worldPoint );
          transform.position = vect;
     }

}

And the results expected happened. Hope other find this useful and thanks again Jo!

Regards,

– Clint