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 KittyKatKat · Apr 06, 2014 at 05:49 PM · physicsraycast

Raycast 360 degree check?

 if (Physics.Raycast (transform.position, Vector3.left, out hit, 2f)
             || Physics.Raycast (transform.position, Vector3.right, out hit, 2f)
             || Physics.Raycast (transform.position, Vector3.forward, out hit, 2f)
             || Physics.Raycast (transform.position, Vector3.back, out hit, 2f)) {
                 if (hit.transform.tag == "Enemy") {
                     faces [0].renderer.enabled = false;
                     faces [3].renderer.enabled = true;
                 }
         } else {
             faces [0].renderer.enabled = true;
             faces [3].renderer.enabled = false;
         }

So, (obviously) I checked the raycast on up, down, left and right, but then I saw that with this kind of coding, raycast doesn't watch diagonally.

So, my question is simple (hopefully the answer is as well), is there a way for the raycast to check a full circle around the player/GameObject instead of just doing what I did above (which, from the size of the If statement, I can already guess is pretty wrong, but hey, gotta start from somewhere, right? :)

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

1 Reply

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

Answer by Griffo · Apr 06, 2014 at 06:31 PM

You could try using this

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 KittyKatKat · Apr 06, 2014 at 07:38 PM 0
Share

I tried using it, but unsuccessful, sadly, since the SphereCast isn't actually a sphere around the player, but a simple thick raycast. $$anonymous$$aybe I'll use a raycast based on sin and/or cos. $$anonymous$$ake both circle for the duration of 270 - 360 radians. I'll see what happens.

Thanks for the answer in any case! :)

avatar image Griffo · Apr 06, 2014 at 08:17 PM 0
Share

What about Physics.OverlapSphere and use layers to take out the player.

avatar image Griffo · Apr 06, 2014 at 08:29 PM 1
Share

Something like this

 #pragma strict
 
 private var whenNeeded : boolean;
 
 function Update(){
 
     if(whenNeeded){
     
         DetectEnemy(transform.position, 20);
     }
 }
 
 function DetectEnemy(center: Vector3, radius: float) {
     
     var hitColliders = Physics.OverlapSphere(center, radius);
 
     for (var i = 0; i < hitColliders.Length; i++) {
         print(hitColliders[i].tag);
         // collect information on the hits here
     }
 }
avatar image danieltdf Griffo · Oct 29, 2015 at 01:03 PM 0
Share

You sir...are a genius...thank you!

avatar image KittyKatKat · Apr 06, 2014 at 10:12 PM 0
Share

It works! Thanks you very much! :) I tried putting it in C#, just because I got used to it (not a rocket science, so it was successful), but the idea works very well!

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

23 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

Related Questions

SphereCast Arguments 1 Answer

Debug.DrawLine problem 1 Answer

Having a RaycastHit event create a component? 1 Answer

Problem With RayCast 3 Answers

thousands of raycasts in nested for loop 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