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 /
  • Help Room /
avatar image
0
Question by nrocpop · Apr 01, 2018 at 08:17 PM · raycasts

Can Someone explain why the racast is only hitting the on the first two collisions.

The issue i am having is that when I attempt to use a ray to check for colliders I am only hitting the first two times. the test environment is set up with a generic plane, and two cubes on top of the plane. These objects are placed in a straight line on the x-axis. The first two rays hit the plane an report the correct information and translate the ray to the appropriate position. The third ray misses the plane. removing the fail checks runs the loop and translates the ray all 100 times successfully yet fails to hit after the first two loops anyway. scaling the plane will cause the ray check to succeed up to 7 times.

What is causing these failures?

        RaycastHit Hit;
        public  Vector3 RayPosition;
        public Vector3 Rayendpoint;
        public float raylength;
        public bool TestDone;
        int Fails;
 
         void Start()
         { 
             RayPosition = new Vector3(0, 10, 0);
             TestDone = false;
         }
 
         void FixedUpdate()
         {
             if (TestDone == false)
             {
             RayChecker();
             }
         }
 
 
         void RayChecker()
         {
 
         for (int i = 0; i < 100f; i++)
         {
             int MaxFails = 10;
             Rayendpoint = new Vector3(RayPosition.x, RayPosition.y - raylength, RayPosition.z);
 
             Debug.DrawLine(RayPosition, Rayendpoint, Color.red, 360f, false);
             if (Physics.Raycast(RayPosition, Rayendpoint, out Hit, 360f))
             {
                 Debug.Log(Hit.collider.name);
                 Debug.DrawLine(RayPosition, Rayendpoint, Color.yellow, 360f, false);
                 Debug.Log(RayPosition + "  :  " + Rayendpoint);
                 RayPosition.x++;
             }
             else if (Fails == MaxFails)
             {
                 break;
             }
             else
             {
                 Debug.Log("FAil");
                 Fails++;
             }
         {
 
         }
 
 
         }
             Debug.Log("LOOPDONE");
             TestDone = true;
 
         }
Comment
Add comment · Show 4
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 meat5000 ♦ · Apr 01, 2018 at 09:08 PM 0
Share

Your debug lines have 360f distance but your Raycast has only 15f. You should also Debug.Log your RayPosition.x

avatar image nrocpop meat5000 ♦ · Apr 02, 2018 at 03:12 AM 0
Share

The 360f is actually a duration in seconds for the DrawLine method. all of the lines are drawn form a start point to an end point so changing the max distance won't actually change much. Also, the debug logs the Vector3 so it returns the X,Y,and Z coordinates.

avatar image meat5000 ♦ nrocpop · Apr 02, 2018 at 12:29 PM 0
Share

Ha my bad :P For me to assume to u made an ass outta me ;) If you have a more completed script I'll gladly try it. In your above snippet RayPosition is undefined so its hard to see whats going on.

Show more comments

1 Reply

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

Answer by nrocpop · Apr 04, 2018 at 03:50 AM

I just realized that i was attempting to define an endpoint(Such as the one called for in the DrawLine method) instead of a direction. By replacing Physics.Raycast(RayPosition, Rayendpoint, out Hit, 360f) with Physics.Raycast(RayPosition, Vector3.down, out Hit, 15f) the ray is hitting as expected. My issue has been resolved.

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

75 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

Related Questions

Why aren't raycasts hitting any colliders? 0 Answers

How to move Raycast Hit Object 0 Answers

Ignore Raycast not working properly? 0 Answers

Raycasting is running in two different objects with the same Tag when I touch just one of them 1 Answer

Multiple raycasts and only two are working 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