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 MakakWasTaken · Jul 12, 2016 at 08:39 PM · raycasttexture2dtexturecoord

RaycastHit.textureCoord always Vector2.zero

This Code:

 for (int y = 0; y < Width; y++)
 {
     for (int x = 0; x < Width; x++)
     {
         RaycastHit Rayhit0;
         Vector3 vertexPos = new Vector3(x,y,0);
         if (Physics.Raycast(vertexPos.normalized * (Radius + MaxHeight),-vertexPos.normalized, out Rayhit0)) {
             q++;                        
             if (q == 500) {
                 Debug.Log ("Position: "+(Rayhit0.textureCoord).ToString() + " Collider Type: " + Rayhit0.collider.GetType().ToString());
             }
         }
     }
 }

Always prints out (No matter what it returns "Vector2(0,0)"):

Debug.Log returns this

screen-shot-2016-07-12-at-223328.png (15.2 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jul 12, 2016 at 08:49 PM

Well, is your mesh actually uv mapped? So does it have uv coordinates? Of course if not it would always return "0, 0".

Comment
Add comment · Show 5 · 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 MakakWasTaken · Jul 12, 2016 at 08:53 PM 0
Share

It is UV-mapped, if I assign a texture to the material that the gameObject uses, it works perfectly fine.

avatar image Bunny83 MakakWasTaken · Jul 12, 2016 at 09:10 PM 0
Share

Your whole code doesn't seem to make much sense. You generate a vector which you normalize, so you only cover a very small area of your mesh. And what's the point of "q"?

You should print out the hitpoint as well se the "vertexpos" to see their values. Also keep in $$anonymous$$d that your raycast is casted in worldspace around the world origin.

Some more context info would help. Is it a 2d or 3d game / application? What kind of mesh is in the center of your world you raycast against? A screenshot wouldn't hurt. Finally what's your goal? Your approach seem a bit strange. You only cover a single "line" around a quater circle.

avatar image MakakWasTaken Bunny83 · Jul 12, 2016 at 09:31 PM 0
Share

The point of q is so that it doesn't print alot to the console (around 16000) so ins$$anonymous$$d I just tried took a sample somewhere on the map. There is 6 identical piece of code to this one which cover the other 5 sides of a sphere.

Finally my goal is to raycast against the sphere, get the normal distance to the middle and then color the map based on this. (I didn't want to post 300 lines of code if around 15 could explain the problem)

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

66 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

Related Questions

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

Canvas UI - Get Pixel Colour from Image 0 Answers

Getting UV coordinate with GraphicRaycaster 2 Answers

Why does my Mesh Collider RayCastHit only return a texturecoord on Unity Remote? 0 Answers

Why do RaycastHit.textureCoord values only appear properly when a layer mask is used? 0 Answers


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