2D Toolkit Forum

2D Toolkit => Support => Topic started by: Khorino on February 27, 2013, 12:10:03 am

Title: Best collider for irregular platforms on mobile
Post by: Khorino on February 27, 2013, 12:10:03 am
Hi guys, so, we have many small sprites so that we can mix many of them to create a platform. The thing is that many are irregular, so a box collider wouldn't work so well. So far, I'm using a mesh collider for those, but the problem starts when one platform has 6 sprites and 6 mesh colliders. Is there someway to avoid that so the performance wouldn't be affected?
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 27, 2013, 12:13:31 am
If its really irregular, and the parts didn't move, why not use the static sprite batcher? It will merge all the colliders into one poly collider.
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 27, 2013, 12:42:32 am
How can I do that?
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 27, 2013, 10:10:42 am
Have you seen this?
http://unikronsoftware.com/2dtoolkit/doc/tutorial/using_the_static_sprite_batcher.html
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 27, 2013, 02:44:58 pm
I've tried to do that and one of the sprites went down in scale (back to 1) and the other one didn't. I redid the configuration and after that, it worked ok, but the problem is that both mesh colliders from both platatforms were still there.

Just to be clear: in the test I tried, I use 2 different sprites to create one single platform. It's like the sprites are "glued" together. In your example, each sprite appear to be one platform, but our assets are really small to do that.

Am I doing something wrong?
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 27, 2013, 03:49:49 pm
Yup, but when committed, the sprites should be merged - so you'll be dealing with one mesh collider instead of however many you would have had prior to the merge. Isn't that what you were looking to do?
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 27, 2013, 04:39:52 pm
Yes. After I press "Commit", the "Game" view still show both colliders (green lines). Is this normal? The colliders still merged but Unity doesn't show them like that?
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 27, 2013, 06:23:25 pm
Yes that is normal. The code doesn't physically merge geometry, but the colliders are "merged" as in there is only one meshcollider. Ideally you want to have as few mesh colliders as possible, so merging these should be hugely beneficial.
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 27, 2013, 06:28:06 pm
Ok, great! Thanks!
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 28, 2013, 06:25:11 pm
Hey, unikron, every time I press "Commit", the scale of children objects go back to 1. Is there a way to avoid that from happening?
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 28, 2013, 07:02:44 pm
The scale is baked in the tk2dSprite.scale parameter - that way it doesn't break batching. Using Unity's transform.scale will break batching. The sprites should appear at the correct size though, if they aren't then that's a bug.
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 28, 2013, 07:43:45 pm
Ok, one more thing: I use the bake scale from 2DTK on the children object. Works fine. But when I use on the main object, the children's position changes. Am I forgetting something?

Thanks for your patience!
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 28, 2013, 08:18:09 pm
Yeah, that is a bit of a complicated case. Scales as applied to transforms cascade (i.e. it is possible to create a skewed sprite by rotating and then scaling the parent). In some cases, you might find that the scale doesn't apply properly.

What is it specifically you're trying to do with the hierarchical scales and stuff? (Just curious - if it is something people tend to use frequently, I'll see if anything can be optimized further)
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 28, 2013, 08:46:16 pm
As I said before, I'm using small sprites to create platforms. For example, sprites 1 and 2 to create platform A.

So, sprite 1 is a game object and 2 is the children. Both would be used on the Static Sprite Batcher.
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 28, 2013, 08:53:34 pm
You're not scaling the static sprite batcher though are you? If not, then all cascaded scales which don't result in skewing will be respected
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 28, 2013, 08:57:25 pm
No, no. The scale problem is already fine. The only problem I'm facing now is when I press "Commit" and the children object (sprite 2) changes its position on the X axis.
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on February 28, 2013, 09:50:41 pm
Please send a simple repro case for this to support@unikronsoftware.com.
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on February 28, 2013, 10:44:07 pm
Ok, I'm trying to replicate the problem on a new project and scene... and I can't! It works fine there, but on my project and scene, it doesn't! How's that possible?
Title: Re: Best collider for irregular platforms on mobile
Post by: unikronsoftware on March 01, 2013, 12:43:54 am
I'm not sure whats happening. Hard to say without seeing it. Can you do a screencast or something demonstrating whats happening? Same email address again.
Title: Re: Best collider for irregular platforms on mobile
Post by: Khorino on March 01, 2013, 01:44:05 am
E-mail is there!  :)