Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by AR_Rizvi · Apr 29, 2016 at 12:22 PM · raycastpositioningminimap

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Outliver · Apr 29, 2016 at 12:35 PM 0
Share

Why would you need to raycast twice? Why would a single raycast via mapCam.ViewportPointToRay() not do what you want?

avatar image AR_Rizvi · May 02, 2016 at 04:53 AM 0
Share

@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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AR_Rizvi · May 04, 2016 at 07:14 AM 0
Share

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

avatar image Outliver AR_Rizvi · May 04, 2016 at 10:00 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

54 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges