Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ayrik · Jan 24, 2011 at 05:14 PM · physicsraycastall

RaycastAll failing inconsistently

Hey everyone, I've been using raycasts just like this with no problem at all, but now they are failing. We are making an RTS and the camera and unit movement works great, but at a certain point in each battle, the raycasts just start failing on random frames. Once it has happened, it does not stop until we stop the game. Sometimes it happens at low framerate times, but other times it just happens near the beginning of the game. Anyway, here is one place I am doing a raycast, it would be nice if someone could tell me I'm doing something wrong, or that they've experienced it before.

RaycastHit[] hitInfo = Physics.RaycastAll(new Vector3(x, maxHeight, z), -Vector3.up, float.MaxValue, TerrainMask);
float highest = WaterLevel;
foreach (RaycastHit hit in hitInfo)
    if (hit.point.y > highest)
        highest = hit.point.y;

Basically, when the raycast fails, it returns WaterLevel. Before I didn't notice this problem, because it was setting the y value to NaN, so the Transform SetPosition failed, disallowing the new position. But now, since I added WaterLevel, it is more visible, and the units and camera jump up and down from the terrain to the water at random.

There is another place I am doing a raycast, and that raycast fails during the same frames as the other. Looks like this:

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hitInfos = Physics.RaycastAll(ray, 3000, SelectionMask | TerrainMask);

However, I realize I am making another raycast that is never failing. This raycast is the only one that goes vertical, and is unlikely to hit the terrain. So it seems that any raycast that hits the terrain, causes the whole raycast to fail, but only every once and a while.

For my workaround, I am going to detect failure and return NaN again, since that seemed to give better results, but a real fix would be great!

Thanks everyone.

Comment
Add comment · Show 1
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 _MGB_ · Jan 24, 2011 at 09:01 PM 0
Share

Sounds dodgy... are you drawing/printing any debug output to try and tell what's happening exactly? $$anonymous$$aybe some Debug lines for the rays - it often helps to visualise things rather than looking at numbers.

1 Reply

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

Answer by Ayrik · Mar 14, 2011 at 08:15 PM

It appears that a divide-by-zero exception was left unhandled during the physics update process, causing the physics system to freak out for the rest of the session. IMO this is a bug in Unity, but the solution was pretty simple, although, hard to find!

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

No one has followed this question yet.

Related Questions

RaycastAll isn't finding all possible collisions 1 Answer

2D 360 degress platformer example needed 0 Answers

Lights that ignore position.z of GameObject 0 Answers

Controlling the physics thread 1 Answer

When a configurable joint object is a fixed joint of another object 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