Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 eric_c · Sep 07, 2012 at 12:41 PM · javascriptraycasttransformraycastallhit.point

RaycastAll - get entry and exit points?

Hi, I'm working on my little project, when I stumbled with something I need help with.

I'm able to use the RaycastAll function to gather information about each collider it detects, but is there any ways that I can get the hit.point of every entry and exit point (indicated by red dots )? Please help in Javascript, thanks!

![http://img59.imageshack.us/img59/5660/unityq.png][1] [1]: /storage/temp/3324-unityq.png

unityq.png (1.8 kB)
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
3

Answer by IMD · Sep 12, 2014 at 11:00 AM

One solution I'm about to implement:

  1. Ensure that a 'backing board' object exists in the far distances / game world border wall which will be picked up in the RaycastAll

  2. Do a forward RaycastAll to get all entry points.

  3. Sort all the entrypoints by their distance value (order is NOT guaranteed by RaycastAll)

  4. To get the exit points of the objects:

  5. Traverse through the entry point array backwards from array.Length - 1 to 0, shooting a simple Raycast from the furthest entry hit point to the second furthest away.

  6. This will provide you with the furthest exit point when it hits the 'back wall' of the second furthest.. etc..

  7. Store these exit points in an exit point array while iterating through all entry points this way.

  8. Remove the furthest hit point from the entry point array as this is the back wall object.

May the source be with you, Isaac :)

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
2

Answer by ScroodgeM · Sep 07, 2012 at 12:51 PM

raycast and physic engine works only with forward faces of colliders, not with backwards. so one way to get exit points is to hit raycast in opposite direction.

Comment
Add comment · Show 1 · 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 KqGMRPFkAeESzF8 · Oct 06, 2021 at 10:34 AM 0
Share

i love you

avatar image
-1

Answer by Fabio Fernandes · Mar 18, 2015 at 06:51 PM

I would like to suggest you a solution I did develop for me.....

Consider the player like a "Hunter", and the caught object like a "Hunted".

You can achieve this by writing a code to the "Haunted" object to start verifying if it is still captured, once it is captured for the first time, like this:


Consider the "Hunter Component" code:

public class HunterComponent : MonoBehaviour {

 public RaycastHit hit;    

 void Update () {
     Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
     if (Physics.Raycast(ray, out hit, 20))
     {

         HuntedComponent component = hit.collider.gameObject.GetComponent<HuntedComponent>();
         if( component != null )
         {
             component.OnCapture(this);
         }
     }
 }

 public bool IsInRay(GameObject outer)
 {
     bool stillIsInRay = false;
     Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
     RaycastHit[] hits = Physics.RaycastAll(ray, 20);
     foreach (RaycastHit outerSearch in hits)
     {
         if (hit.collider.gameObject == outer)
         {
             stillIsInRay = true;
             break;
         }
     }
     return stillIsInRay;
 }

}


and the "Hunted Component" code:

public class HuntedComponent : MonoBehaviour { HunterComponent rayCasterSource; bool selected = false;

 void FixedUpdate () {
     if (rayCasterSource != null)
     {
         if(!rayCasterSource.IsInRay(gameObject))
         {
             OnRelease();
         }
     }
 }

 public void OnCapture(HunterComponent current)
 {
     renderer.material.color = Color.red;
     rayCasterSource = current;
 }

 public void OnRelease()
 {
     rayCasterSource = null;
     renderer.material.color = Color.white;
 }

}

I hope this solution helps you guys

Bests regards

Comment
Add comment · Show 1 · 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 Leoo · Jul 07, 2015 at 11:55 AM 0
Share

Dude, you don't even know what are you talking about, thinking about adding a component to EVERY object the man has on his scene to make it work? ... please. This is a very bad response, please dont use this, bad performance and horrible scalability.

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

11 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

Related Questions

Disabling a lineRender or Ray when there is no target 1 Answer

Object following mouse problem 1 Answer

Raycast collided object not transforming when scripted to? 1 Answer

Move to closest point in front of player with raycast 0 Answers

Raycast object as far as possible? 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