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 ASE-Lab · Nov 02, 2020 at 04:40 PM · collidersraycasthitboxcolliderocclusion

Collider inside another collider : I have these spheres inside the brain, and I want to be able to move the brain via mouse while being able the click the spheres

alt text The spheres have a sphere collider on them and are clickable via this script:`Clickable.cs` public class Clickable : MonoBehaviour { void Update() { ClickDetect();

 }
 void ClickDetect()
 {

     RaycastHit hit;
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);



     if (Physics.Raycast(ray, out hit))
     {
         Transform t = hit.collider.transform;
       
         if (t.name == "Sphere(Clone)")
         {


          
             if (Input.GetMouseButtonDown(0))
             {
                 
                     hit.collider.gameObject.GetComponent<Light>().color = new Color(1, 0, 0, 0.7f);

                 Debug.Log(t.parent.name + (t.GetSiblingIndex() + 1));
             }



         }
     }
 }}

and the brain has a box collider on it and is moved by this script RotateonMouse
`void Rotation() { if (_isRotating) { // offset _mouseOffset = (Input.mousePosition - _mouseReference);

         // apply rotation
         _rotation.y = -(_mouseOffset.x) * _sensitivity;
         _rotation.x = -(_mouseOffset.y) * _sensitivity;

         // rotate
         transform.eulerAngles += _rotation;

         // store mouse
         _mouseReference = Input.mousePosition;
     }

 }


The issue arises when I try to click on the spheres when the box collider on the brain is on. I end up rotating the brain instead of being able to click the spheres. Is there a way to be able to click inside the collider while also on the collider to rotate the brain?.

brain-for-question.png (101.2 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AltaNox · Nov 02, 2020 at 05:46 PM

A way to solve this is to handle both of these behaviors in a single script so you can more easily give precedence to one of them. Otherwise you'd need a third script that oversees both of them to achieve this.


So, my suggestion is to move the code from the Rotation method inside RotateOnMouse to the ClickDetect method (and rename it if you deem it appropriate). After you do that make sure that the Rotation code will execute if and only if you failed to hit a sphere with the raycast. This way, only 1 of the 2 actions can happen at once, and the sphere clicking will have precedence.

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 ASE-Lab · Nov 02, 2020 at 07:30 PM 0
Share

@AltaNox So I tried what you had suggested, but I have to move inside the box collider of the brain to click the spheres, the brain collider is intercepting all the clicks. The spheres are children of the brain and are effectively covered by its collider. Is there something I'm missing? Thanks for your help

avatar image
0

Answer by madalenaantunessousa · Apr 19 at 01:32 PM

Hello @ASE-Lab! I know this topic is from quite a while but I've run into this exact problem and was wondering if you've managed to solve it and how? Thx!

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

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

Related Questions

Why is it so fast to move objects with collider collisions? 1 Answer

Raycast is not returning exact number / Mesh is not exact dimensions 2 Answers

RaycastHit: What is the difference between hit.transform.tag and hit.collider.tag, and which should I use when? 1 Answer

A script that auto generated the box collider around a 3d model 3 Answers

Ray cast affects all colliders in scene if mouse button is not releasesd. 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