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 faizan_raza93 · Feb 01, 2020 at 06:40 PM · raycastplanescreentoworldpointinput.mousepositiontexturecoord

Find TextureCoordinates from plane with out raycast only using mouse position on plan

Hello Guys. Wel I'm stuck and don't know what to do now,I will be very glad if any one of you help me. So I am working on a drawing feature of my app,It has a plan generator that generate 3Dplanes like grid .these tile contain Images on them .What I do is get the texture coordiantes by hitting Ray on the collider of plane and get the UV of that mesh and multiplying that UV by tex width and height to find pixel at that point of hit and assigning it to my Paint function. if (Input.GetMouseButton(0)) { if (Physics.Raycast(ray, out hit, 100f)) { Debug.DrawLine(ray.origin, hit.point, Color.blue, 2f); Renderer rend = hit.transform.GetComponent<Renderer>(); MeshCollider meshCollider = hit.collider as MeshCollider; if (rend == null || rend.sharedMaterial == null || rend.sharedMaterial.mainTexture == null || meshCollider == null) return; Texture2D tex = rend.material.mainTexture as Texture2D; Vector2 pixelUV = hit.textureCoord; pixelUV.x *= tex.width; pixelUV.y *= tex.height; Debug.Log("UV of hit point" + hit.textureCoord); Debug.Log("Hit Point is "+ hit.point); Debug.Log("Vector3 Point is " + CursorOnTransform); DrawableObj.GetComponent<DrawViewController>().Paint(pixelUV); // } } }

but I have problem it works fine on one tile but when shifting tile .The problem is the ray is coming from camera on mouse position but when we move mouse faster then it skip alot of position e.g if on first frame the mouse is on left tile at some position then on next frame it is on next tile at some position...So to remove this constrant I ha convert the mouse position to a position on a plane Now I have a vector3 which is on the same position where my mouse is over the plan.I got this vector3 by this method......... public Vector3 cursorWorldPosOnNCP { get{ return Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,Camera.main.nearClipPlane)); } } public Vector3 CameraToCursor { get{ return cursorWorldPosOnNCP - Camera.main.transform.position; } } public Vector3 CursorOnTransform { get { /* ParentPlan is and empty gameObject which have all the generated plan as child */ Vector3 camToTransform = ParentPlan.transform.position - Camera.main.transform.position; return Camera.main.transform.position + CameraToCursor * (Vector3.Dot(Camera.main.transform.forward, camToTransform) / Vector3.Dot(Camera.main.transform.forward, CameraToCursor)); } } there is one thing

hit.point and Vector3 globalPoint = CursorOnTransform;

is same Now I want to get the texture coordinates of the plan that is under this globalPoint How I can Find it??? ![alt text][1] [1]: /storage/temp/152139-hitonplan.jpg
hitonplan.jpg (272.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

168 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Alternative to ScreenPointToRay needed 1 Answer

How to hit two object with one raycast? 2 Answers

What does it mean if my RaycastHit.texturecoord changes dramatically on either side of adjacent triangle edges? 0 Answers

How to make an object rotate to raycast hit from mouse? Unity 3D 1 Answer

Plane.Raycast for mouselook won't work in positive y-axis 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