Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: johns on December 03, 2014, 03:57:37 AM

Title: Moving sprites ignore colliders
Post by: johns on December 03, 2014, 03:57:37 AM
Hi, I have the following setup:

3D scene

1. Non-NGUI static object with a box collider.
2. NGUI sprite with a box collider, and a rigidbody attached.

When I start the game the sprite falls right through the box collider. Collisions are set up properly in the layer collision mask. The layers are also set properly to they should collide.

If I make a regular cube, add a rigidbody to it and launch the game, the cube collides properly with the collider. However if I add a NGUI sprite component to the cube it stops colliding. If I then remove the sprite from the cube it won't collide as well.

As I understand, NGUI changes some physics settings internally (Collider/Rigidbody?). What can I do to make the sprites collide properly with other static colliders?

Thanks.
Title: Re: Moving sprites ignore colliders
Post by: ArenMook on December 04, 2014, 03:24:37 AM
NGUI colliders are all marked as triggers, which don't have collision. Also, NGUI works with 3D colliders by default -- flat 3D colliders to be precise. If you want collision, you need to give them a volume by adding a 3rd axis.
Title: Re: Moving sprites ignore colliders
Post by: johns on December 04, 2014, 05:27:48 AM
The first thing I did is made the collider non-trigger, and made collider's Z-size equal to 50. Still no success.

Maybe the system internally somehow marks all of the attached colliders as trigger which doesn't show up in the inspector?

Thanks.
Title: Re: Moving sprites ignore colliders
Post by: ArenMook on December 05, 2014, 12:36:24 AM
Check your physics collision layers. UI layer by default doesn't collide with anything.
Title: Re: Moving sprites ignore colliders
Post by: johns on December 05, 2014, 04:51:59 AM
The layers are set up properly. UI collides with UI.
Title: Re: Moving sprites ignore colliders
Post by: johns on December 05, 2014, 06:07:30 AM
As I said non-NGui objects collide properly. Simply adding a UIWidget breaks them forever.
Title: Re: Moving sprites ignore colliders
Post by: ArenMook on December 05, 2014, 03:22:57 PM
I just did the following test:
1. New scene.
2. ALT+SHIFT+S, ALT+SHIFT+C.
3. Changed the whole UI to be on the Default layer, deleted the main camera, made the UI camera draw the Default layer instead and changed its clear flags to Skybox.
4. Turned off "Trigger" on the sprite.
5. Added a rigidbody to the sprite.
6. Duplicated the sprite.
7. Moved the second sprite down, tilted it, and enlarged it to create a wide platform.
8. Checked the "kinematic" flag on the 2nd sprite.
9. Unchecked "Collider" option on the widget so that collider size wouldn't be reset.
10. Changed the collider's Z to 100 to give it volume.
11. Hit Play, one sprite falls on top of the other and stays there.

My guess is you forgot #9.