x


How to detect colliion if a parent is an empty object and children are cubes

I just started learning unity and trying to implement tetris. But I encountered the following issue:

As you can see at the screenshot I have Z object. Z is an empty object without any components. It consist of 4 cubes with enabled Box Collider as children objects. Level is an empty object too. Bottom/Top/Right/Left Borders are Cubes

How to detect collisions of Z with Level object?

I tried to add OnCollisionEnter to child cubes but it is not called.

alt text

tetris.jpg (101.8 kB)
more ▼

asked Jul 13 '12 at 11:55 PM

Gennadiy gravatar image

Gennadiy
1 2

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The thing you want to have an OnCollisionEnter on needs to have a rigidbody attached - you can set it to isKinematic = true to it doesn't move with physics.

more ▼

answered Jul 14 '12 at 11:09 AM

whydoidoit gravatar image

whydoidoit
33k 11 23 98

I tried to add a rigitbody to Z object and set isKinematic = true but OnCollisionEnter still was not called for Z object as well for child cubes.

Jul 14 '12 at 12:24 PM Gennadiy

From the screen shot it appears your colliders are set to isTrigger - if that is the case you only get OnTriggerXXX functions not the OnCollisionXXX

Jul 14 '12 at 02:24 PM whydoidoit

I was experimenting and forgot to uncheck isTrigger but I tried both cases and still without success.

Jul 14 '12 at 03:22 PM Gennadiy
(comments are locked)
10|3000 characters needed characters left

How I resolved this issue.

I set isTrigger = true for box colliders of Left/Right/Bottom/Top borders. Added a rigidbody component to Z object. Set isKinematic=true for the rigitbody. Added OnTriggerEnter handler to Z object.

more ▼

answered Jul 16 '12 at 05:04 PM

Gennadiy gravatar image

Gennadiy
1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2485

asked: Jul 13 '12 at 11:55 PM

Seen: 239 times

Last Updated: Jul 16 '12 at 05:04 PM