Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by MasterBLB · Jul 11, 2011 at 03:01 PM · meshclickpoint

Weird coordinates when cllicking on collider and convert to mesh point

Hi all

I'd like to find clicked point on my mesh.I wrote code:

 void OnMouseUp()
 {
     RaycastHit hit;
     if(Physics.Raycast(Input.mousePosition,transform.position,out hit))
     {
         infoText.text="hit on:"+hit.point.ToString();
     }
 }

well,it works but it gives me coords in world space,not mesh ones :/

I read docs,make research on this forum,ask few questions and find out that such shoud convert world's hitpoint coordinates into mesh local:

 infoText.text="hit on:"+transform.InverseTransformPoint(hit.point).ToString();

But this gives me unacceptable results-if I move my mouse cursor about a centimeter in any direction I still get the same coordinates :/ Such issue does not appear if I check the point in world's space-change mouse position even a milimeter is noticeable and gives other point coords.

Who knows what can cause the issue?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MasterBLB · Jul 12, 2011 at 10:05 AM

I solved the issue on my own-there were too small scale set on FBX Importer.

Comment
Add comment · 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
0

Answer by Bunny83 · Jul 11, 2011 at 03:15 PM

I never had problems with that. Have you tried to log both the world and local coordinates? It's kinda inpossible that one is changing and the other stays. Btw: ToString is called implicitly when it's used like a string

 infoText.text = "hit w:" + hit.point + " l:" + transform.InverseTransformPoint(hit.point);
Comment
Add comment · Show 9 · 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 Bunny83 · Jul 11, 2011 at 03:16 PM 0
Share

And make sure you don't have "collapse" enabled at your console window.

avatar image MasterBLB · Jul 11, 2011 at 03:29 PM 0
Share

I have no idea how it's possible,but I did as you suggested and logged both coordinates-as before,the world's ones changes and the mesh's not :/

And tell more please about that collapse option

avatar image Bunny83 · Jul 11, 2011 at 04:30 PM 0
Share

The collapse button will hide similar messages. It happens regularly that people think their code is only executed once because there's only one line in the console. Sometimes it's useful when you still have a Debug.Log somewhere in Update().

I just realized that you use a GUIText or Text$$anonymous$$esh so the collapse button is irrelevant ;)

It sounds really strange, are you sure you use the right transform? You have to use the one of the $$anonymous$$esh. If you do a raycast from another object transform will be the transform of that other object and not the one of the $$anonymous$$esh.

Use

 hit.transform.InverseTransformPoint(hit.point);

to be on the safe side.

avatar image Bunny83 · Jul 11, 2011 at 04:38 PM 1
Share

I just saw that you use Physics.Raycast absolutely wrong ;). It works always in world space and the first argument have to be a position in 3d from where you want to start your raycast. The second argument is a direction, not a position.

In your case you would use Camera.main.ScreenPointToRay to get a Ray and use that one with Raycast.

 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 if(Physics.Raycast(ray,out hit))
 {
     [...]


The mouseposition is in screencoordinates and therefore only 2D ;)

avatar image Bunny83 · Jul 12, 2011 at 03:26 AM 1
Share

I've created a test scene for your case and turned it into a web-build. The source package of the scene can be found at the bottom of the build.

Like i said i have no problems with the Raycasts. $$anonymous$$aybe you're a bit confused by the vector that is displayed when you use ToString() of a vector3. ToString will round x, y and z to 0.1 accuracy. $$anonymous$$y test scene displays the local and world coordinates two times. The first one is just Vector3.ToString and the second one is manually converted (component wise).

Since the sphere that comes with Unity has a radius of 0.5 all local coordinates will be between -0.5 and 0.5. $$anonymous$$eep in $$anonymous$$d that if you scaled the sphere by 100 so it has a radius of 50, the local coordinates are still only 0.5

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to increase thickness of points? 1 Answer

Rendering Mesh Points on Mobile 0 Answers

is there any way to track the position of a certain point in the mesh of a capsule object? 1 Answer

How do you use a queuing mechanism in Unity? 1 Answer

Character keeps walking to origin with Raycast? 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