- Home /
Select object through Mini Map in world Space
I am making a mini map Using render texture to render my Over head cam to my screen and Drawing that texture using NGUI 3.9 every things is fine Apart from When i am Trying to click on My minimap and trying to destroy a object or Geting the point on my Game Floor which is on my World Space rendered by Main Camera Raycast is not reaching it some how i don't know what i am doing wrong Edited: I am using Ngui is because whole Gui of my game is in Ngui so its my requierment
I have Edited my code to a new aproch by this i am able to cast a ray on to my floor but the position of my ray is not accurate
here is my code
public void TestWithTextureCoords() { Camera main = UICamera.mainCamera;
Camera mapCam = transform.GetComponent<Camera>();
Ray firstRay = main.ScreenPointToRay(Input.mousePosition);
Debug.DrawLine(firstRay.origin, firstRay.direction);
RaycastHit textHit;
if (Physics.Raycast(firstRay, out textHit, main.farClipPlane))
{
var hitPoint = textHit.point;
Ray scondRay = mapCam.ViewportPointToRay(hitPoint);
RaycastHit worldHit;
if (Physics.Raycast(scondRay, out worldHit, mapCam.farClipPlane))
{
Debug.DrawLine(scondRay.origin, worldHit.point, Color.red);
Debug.Log(" world hit point " + worldHit.point);
Debug.Log(worldHit.transform.name, worldHit.transform);
}
}
}
Please look into it As soon as possible let me know a work around or how it is being done May be I am missing a small Think I have no idea about I have Tried different kind of approaches but all in vain help!
Why would you need to raycast twice? Why would a single raycast via mapCam.ViewportPointToRay() not do what you want?
@Outliver i am raycasting twice becuse first gives me the screen position on $$anonymous$$imap from which i have to cast another ray from mapCam to Floor that why i am using two ray cast and my $$anonymous$$imap is being displayed by another camera which is a gui camera
Answer by Outliver · May 02, 2016 at 10:34 AM
I'm pretty sure your minimap is beeing generated at runtime. So why not just add a component to each minimap object that contains a reference to the original GameObejct? You could then trigger whatever function whenever the map-object is hit by the ray.
Having that said, it seems as if you mixed something in your code. Why do you cast a ray in "global scope" BEFORE you do the raycast on the minimap? Wouldn't the other way around be a much more fitting solution?
How can i cast a ray in world space first as i have to select my object through $$anonymous$$i map the screen position will never favor me in this method
and for other how to display a object on $$anonymous$$imap On that exact location where its Reference is placed on world space and after that i have to select it though thru $$anonymous$$i map
How can i cast a ray in world space
Why would you need to do that? How's your $$anonymous$$imap working? Do you have an excerpt of your code?
The idea is the following:
Whenever a $$anonymous$$imap item is rendered, add a component (like "$$anonymous$$ini$$anonymous$$apObject") that holds a reference to the original GameObject
Whenever the $$anonymous$$imap is clicked, do a raycast
Whenever the ray hits a $$anonymous$$imap item, execute some method of some component of the original GameObject
Your answer
Follow this Question
Related Questions
Raycasting on render texture, minimap 1 Answer
Translating main camera co-ords to minimap? 0 Answers
Smooth rigidbody movement 2 Answers
project view frustrum of camera onto plane as white rectangle 0 Answers
How to position UI elements on the Minimap's rectangle relative to the elements target position? 1 Answer