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 idlemurmurs · Aug 03, 2014 at 07:41 AM · collisionraycasttriggerhit

Receiving information about getting hit by a Raycast

Good morning, afternoon, evening . . . night!

This may well be quite an inexperienced and foolish question, so bear with me here.

Though I'm currently considering the possibility of messing about with raycasting. And therein lies my question. as though it's possible to receive information about which objects the ray has undoubtedly collided with. Is it possible to receive information if your desired collider has been hit by a raycast?

Similar in sense that you can track/trigger generic collisions, is it possible to track raycast collisions outside of the script that initiated it?

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 Firedan1176 · Aug 03, 2014 at 07:47 AM 0
Share

Sorry, but no. You can just simply have the script that instantiated the raycast to toggle a bool or whatever to do so. But outside the instantiated script, it's kind of pointless unless you're not able to tell it that it got hit.

2 Replies

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

Answer by robertbu · Aug 03, 2014 at 07:45 AM

There's no standard feature for this functionality, but it is trivial for the Raycaster to inform a script on the object it hit that the hit occurred. It can be done using GetComponent() or SendMessage() in just a line of code or two assuming there is a script on the objects with the collider to 'receive' the information. In C# you could use Events and Delegates to inform any script that wanted to know what object(s) are hit.

Comment
Add comment · Show 2 · 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 idlemurmurs · Aug 04, 2014 at 06:55 AM 0
Share

Thank you so much for the response,

Though it's the answer I was secretly hoping for, it's definitely still a relatively beneficial answer all the same.

It's a shame no such standard feature yet exists, though this shouldn't (hopefully) be too much of an issue

avatar image Kiwasi · Aug 04, 2014 at 07:25 AM 1
Share

No reason you can't extend physics to let you add your own raycast that does this. Then you can pretend its standard.

avatar image
0

Answer by idlemurmurs · Aug 08, 2014 at 06:17 AM

Discovered/Designed a potential answer to my own mullings,

So here's merely how I've chosen to undertake that particular issue (for anyone who may need it):

 private DesiredScriptName  scriptCommunication; 
  
 
 // =============================================== //
 // Designates A Permanent Raycast That Will Determine Whether The Desired GameObject Has Been Collided With
 // Allows Direct Communication With The Specific "Desired" GameObject That Was Interacted With
 
 if (Physics.Raycast (transform.position, directionRay, out collisionRay, distanceRay) ) 
     {     
         if (collisionRay.collider.gameObject.tag == "Desired GameObject Tag" )
         {  
         scriptCommunication = destinationTransform.gameObject.GetComponent <Desired Script> ();
         scriptCommunication.designatedboolean = true; 
         }
     }
 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Prevent shooting when gun is inside wall 1 Answer

Detecting if object1, being hit by raycast, is colliding with another object 0 Answers

DontGoThroughThings vs Triggers 1 Answer

get the point directly above the raycast collision? 1 Answer

Best method to detect sword hits 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