Hello Guest

Author Topic: Best collider for irregular platforms on mobile  (Read 10778 times)

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Best collider for irregular platforms on mobile
« 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #1 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.

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #2 on: February 27, 2013, 12:42:32 am »
How can I do that?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #4 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #5 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?

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #6 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?
« Last Edit: February 27, 2013, 06:28:32 pm by Khorino »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #7 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.

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #8 on: February 27, 2013, 06:28:06 pm »
Ok, great! Thanks!

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #9 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #10 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.

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #11 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #12 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)

Khorino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #13 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best collider for irregular platforms on mobile
« Reply #14 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