RenderTexture - Raycast problem

Hey forum members,

I have a problem with the hit detection on a rendertexture, let me explain.

I’ve created a rendertexture and added it to a secondary camera(called minimapCamera). This camera is targeted to a plane to simulate a Minimap.
Inside the view of this camera I’ve added some other GameObjects which the user should be able to click.

In my main view I’ve added a GUI-Texture and used the rendertexture as it’s material so I can show my minimap on the screen.
I attached a script to this Gui-Texture which has an OnMouseDown event and added the following code:

Ray ray = minimapCamera.camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log(“hit.transform.name”);
}

I’m also drawing a Line to see where I clicked using the ray.origen and hit.point.

But when I click my minimap it returns the “wrong” transform and the line gets drawn to places it shouldn’t .

Could anyone help me figure out what i’m doing wrong?
As you can see I’m using minimapCamera.camera.ScreenPointToRay so it should be ok.

Thx guys

there’s a difference between Input based mousePosition and GUI based mousePosition

have a look at:

Hey,

Thanks for the quick response but what should I actually do with the mouseposition event?
Since this is a vector2 and i need a vector3 to use for the Raycast.

Thx.

Hi Hammersr,

Why not use the popular KGFMapSystem? It is triggering C# events every time you click into the map, onto a mapicon or when you place an own bookmark into the minimap. We are developing and supporting the KGFMapSystem nearly a year now so we already solved the most minimap- problems out there. :slight_smile:

And: At the moment is a short time SALE: only 25$ instead of 65$!

If you need more info or if you have any questions just contact me as support@kolmich.at or checkout our documentation or forum

Best wishes,

Michal

Hey,

Thanks for the reply but I already fixed it myself:)
Thats a nice Mapsystem you got there btw

thx!