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 Razion · Jul 23, 2012 at 07:15 PM · raycastaicrashraycasting

Raycasting crashing Unity?

I've got a script that (while a player hasn't been sighted) sends out various raycasts. If one of these raycasts hits a player, the loop ends and the AI should begin to give chase. The chase portion of the script does nothing right now, but something is causing Unity to crash when I click "play".

Edit: Despite using the code format button, my code formatting gets destroyed. Any help with making that more readable would be appreciated, too. ;]


void Search(){ RaycastHit hit;

Vector3 rayPos = transform.Find ("rayPos").position;

Vector3 right15 = Quaternion.Euler(0, 15, 0) transform.forward; Vector3 right30 = Quaternion.Euler(0, 30, 0) transform.forward; Vector3 right45 = Quaternion.Euler(0, 45, 0) * transform.forward;

Vector3 left15 = Quaternion.Euler (0, -15, 0) transform.forward; Vector3 left30 = Quaternion.Euler (0, -30, 0) transform.forward; Vector3 left45 = Quaternion.Euler (0, -45, 0) * transform.forward;

// [LINE OF SIGHT CHECKS] // Forward

while(playerSighted != true){ // Forward if(Physics.Raycast(rayPos, transform.forward, out hit, 30.0f)){ Debug.Log("Hit: 0 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } }

// 15 degrees right if(Physics.Raycast(rayPos, right15, out hit, 26.0f)){ Debug.Log ("Hit: 15 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } }

// 30 Degrees right if(Physics.Raycast(rayPos, right30, out hit, 22.0f)){ Debug.Log ("Hit: 30 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } }

// 45 Degrees right if(Physics.Raycast(rayPos, right45, out hit, 18.0f)){ Debug.Log ("Hit: 45 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } }

// 15 degrees left if(Physics.Raycast(rayPos, left15, out hit, 26.0f)){ Debug.Log ("Hit: -15 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } }

// 30 degrees left if(Physics.Raycast(rayPos, left30, out hit, 22.0f)){ Debug.Log ("Hit: -30 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } }

// 45 degrees left if(Physics.Raycast(rayPos, left45, out hit, 18.0f)){ Debug.Log ("Hit: -45 Degrees"); Debug.DrawLine(rayPos, hit.point, Color.green); if(hit.collider.tag == "Player"){ playerSighted = true; } } }

if(playerSighted == true){ Chase(); }

}


Apologies for that being lengthy. Any ideas would be greatly appreciated. Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by m.alekseev · Jul 23, 2012 at 09:00 PM

Check if you have collider on your player object. Or maybe any ray catches other game object, which doesn't have collider.

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

Answer by Razion · Jul 24, 2012 at 08:23 AM

Turned out to be an issue with unity not liking the way I was making the raycasting conditional. Not quite sure why.

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

Answer by Sphax84 · Nov 28, 2016 at 12:31 AM

I get a crash on "Physics.Raycast (ray, hit)" as well on x64 (not tested on x86) when many raycasts are achieved in a loop. This happens in editor while playing or in standalone exactly the same.

Related thread: http://answers.unity3d.com/questions/240483/raycast-crashing-build-on-collision-with-mesh-coll.html#answer-1277231

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Another Raycast Issue. 0 Answers

Finding RayCastHit's Origin Position 2 Answers

Diagonal Raycasting to detect platform returns true, even when false 1 Answer

AI Raycast problem 1 Answer

Raycasting and enemies ai 2 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