- Home /
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.
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!
You will need to change GeometryType from Outlines to Polygons or increase the Edge Radius above 0.
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.
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.
Just setting the Collider2D to polygons should be enough, so long as your rigibody is being simulated.
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
Follow this Question
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
Move a tile (sprite) with drag and drop in Unity 2D 0 Answers
useAutoMass and child objects 1 Answer
How to Maintain Constant Velocity of a Moving GameObject? 0 Answers