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
0
Question by Narnialover · Aug 06, 2018 at 04:33 PM · raycastingrayscreenpointtoray

Ray Travels Incredibly Short Distance -- Unity 5.5.0f3 -- Windows 8.1 -- Solved Sort-of

Hi! I'm definitely still learning about Unity so this may be a really dumb question and I'm missing something incredibly obvious. If I am, I'm sorry but I've looked around a bit online and done some experimenting in Unity and I cannot figure out what's wrong.

I'm following a tutorial here (https://catlikecoding.com/unity/tutorials/hex-map/part-1/) about how to create a hex map. I've tried a couple other tutorials on that site and I've run into some glitches. I figure it's probably because the person making the tutorials is using all different versions of Unity and I'm not. I've been able to work most of them out but I'm stuck on this one.

The section of code that the problem is in is this one:

     void HandleInput () {  
     Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     if (Physics.Raycast(inputRay, out hit)) {
         TouchCell(hit.point);
     }
 }

If I understand what's supposed to be going on, when this function is called (whenever I click), the camera shoots out a ray towards the point that I clicked on. If it hits something, it returns that and calls the TouchCell function. The TouchCell function changes the color of the cell and it's pretty obvious that that's not happening. I did some experimenting and some online research, and went down some dead ends. It's making it up to the if statement but not making it in. I think that means my ray isn't hitting anything. I've found out out why. The ray is so tiny it's invisible to the naked eye. I've tried multiplying its direction but the only difference that multiplying it by 150 makes is a change of 0.1 in the z. I don't understand what's going on. Can anyone please explain? Thanks!


Edited: I have come to the conclusion that rays make no sense and I just don't understand what's going on. But I reached the level of desperation where you just start clicking things and seeing what happens and I found out that toggling the mesh collider being convex on and off makes the next raycast work. I don't know why, I don't know what the problem is and, frankly, as long as I can make it work, I don't care but, if anyobody knows what causes this, it would be useful to know. Thanks! Sorry for bothering you.

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 SynergyStudios · Aug 06, 2018 at 05:13 PM

 public float range = 300;
 
 void HandleInput () {  
          Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
          RaycastHit hit;
          if (Physics.Raycast(inputRay, out hit, range)) {
              TouchCell(hit.point);
          }
      }

chane the values of the range variable.

this might work, but i dont know. i am an intermediate coder, so i only know some stuff. hope it works!

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

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

93 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

Related Questions

camera.ScreenPointToRay always has same origin... 1 Answer

Checking if object stopped being hit by Raycast while overlapping another object of the same type. 0 Answers

Ray. Find Point without Physic Collision! 0 Answers

Why is the camera.screenpointtoray off? 1 Answer

Problem with raycast distance 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