Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by Gandarufu · Nov 10, 2018 at 07:35 PM · rigidbody2dcollider2ddrag-and-drop

OnMouse Events for Composite Collider with Rigidbody2d

I'm trying to assemble Tetriminos, made of smaller mino blocks, and add a collider to the parent object via a Composite Collider 2D.

alt text

For whatever reason, however, I cannot get any OnMouse Events to work on the parent object with a Rigidbody2D attached to it, for instance:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DragRigid : MonoBehaviour {
 
      public void OnMouseEnter()
      {
          Debug.Log ("Started");
      }
 }
 

Does anyone see what the problem ist here? Are the setting for the Composite Collider 2D wrong, or the ones for the Rigidbody 2D? As far as I understood, OnMouse Events should also work in both cases, but in my case they don't. This seems to be so simple, yet I have searched everywhere and I can't find the problem.

I'd appreciate any input!

dragrigidbody.jpg (243.7 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 CraigGraff · Nov 10, 2018 at 08:18 PM 0
Share

You will need to change GeometryType from Outlines to Polygons or increase the Edge Radius above 0.

avatar image Gandarufu CraigGraff · Nov 10, 2018 at 08:30 PM 0
Share

Unfortunately nothing changed. The script works on any element with just a collider, but as soon as there is a Rigidbody it seems to override all children's colliders. I have read about it and am aware of it – I still think it that the script should work if I attach it to the parent object with a rigidbody though.

1 Reply

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

Answer by Gandarufu · Nov 10, 2018 at 09:06 PM

I think I found the solution: The rigidbody2d needs to have "Simulated" checked and be dynamic (set gravity scale to 0), and the Composite Collider 2D needs to be set to Polygons.

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 Hauthorn · Apr 24, 2019 at 02:30 AM 0
Share

Just setting the Collider2D to polygons should be enough, so long as your rigibody is being simulated.

avatar image SaulChow · Sep 07, 2021 at 01:09 PM 0
Share

I got the same problem. Thanks for your experience. And I found the "dynamic" is not necessary, "static" also works. The Geometry Type "Polygons" is must. I think Polygons is solid, so that can be detected for mouse raycast (line-plane). Outline mode is just lines, not solid. So can not detect outline and raycast line from different plane which are perpendicular(line-line).

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

100 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

Related Questions

How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer

Detect onMouseDown() on children colliders of a rigidbody parent 2 Answers

Drag and drop collisions 1 Answer

Move a tile (sprite) with drag and drop in Unity 2D 0 Answers

useAutoMass and child objects 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