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 DinostabOMG · Jan 04, 2014 at 06:37 AM · collidereventonmousedown

How can I prevent an invisible collider from intercepting an OnMouseDown() event?

In the game I'm building, I need the user to be able to click on the black sphere object shown here:

alt text

However, because in this game the objects are supposed to pile up on the platform underneath, I have put up some invisible kinematic rigidbody walls.

alt text

The problem is that the OnMouseDown() event is not being triggered in most cases because the invisible walls are in the way. I believe this is the case because there are some gaps in the walls and if I click in between the gaps, the event executes.

How can I get it so that the invisible walls are ignored for the purpose of triggering the black sphere's OnMouseDown() event, but still behave as a kinematic object that prevent the boxes and sphere from falling off the platform?

gameview.png (301.1 kB)
inviswall.png (441.0 kB)
Comment
Add comment · Show 2
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 XDeltas · Jan 04, 2014 at 06:41 AM 0
Share

Fire a raycast that ignores the walls. then return the name of what it hit

avatar image robertbu · Jan 04, 2014 at 06:59 AM 0
Share

I'm giving this as a comment since it is untested. Can you put your walls on the 'Ignore Raycast' layer? Another possibility is to build the walls out of plane mesh collider rather than box colliders. mesh colliders are one sided.

2 Replies

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

Answer by valim · Jan 04, 2014 at 12:37 PM

Use a raycast. Here's a bit of code that can help: You should put the sphere into a new layer and whatToCollideWith should be only that layer.

   public float distanceLimit = 10000f;
   public LayerMask whatToCollideWith;
 
   void Update(){
    if(Input.GetMouseButtonDown(0)){
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     if (Physics.Raycast(ray, out hit, distanceLimit, whatToCollideWith)) {
      // Clicked();
     }
   }

You should rename the OnMouseDown to Clicked, or any name.

I didn't tested myself.

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 XDeltas · Jan 04, 2014 at 08:31 AM

Use a raycast to test if your click would hit the ball and set the walls to Ignore raycast layer and you could try robertbu's suggestion to use a plane mesh collider. Then depending on what happens after the ball is clicked, you would either have the raycast change a value on the ball and use a script to check when the value changes, or have the balls identified by name and have the raycast output the name of the object hit. Hope this sums up the answer.

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

20 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

Related Questions

onMouseDown call function from other script 1 Answer

Call OnMouseDown of collider? 0 Answers

Can you do an OnTriggerEvent or anything related for instantiated spheres with colliders 0 Answers

Do "whatever" when two colliders enter a trigger 1 Answer

Can't click gameobject when over another trigger? 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