Hello Guest

Author Topic: flip  (Read 13439 times)

Orion

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: flip
« Reply #15 on: November 27, 2013, 12:16:50 pm »
The problem isn't the scale key, but the position keys, when the sprites move. It keeps resetting the z position to "pre-flip".

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: flip
« Reply #16 on: November 28, 2013, 11:04:15 am »
I think I understand, but I'm not sure if there is a clear cut solution to this. You might have to write a manager script to modify z based on flipped state.

Orion

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: flip
« Reply #17 on: November 28, 2013, 06:45:18 pm »
I don't have a problem writing (complex) code, once I know a working solution. Right now I'm trying to find anything that will work without killing performance.

Basically what happens is this:

- Character turns around >> I flip z order of children (once)
- Character gets animated (by mecanim) >> the animation restores the pre-flip z order

Right now the only way to avoid that would be to reorder the sprites on LateUpdate, after the animation happened. But I can imagine reordering 1000s of sprites every frame is not going to be good for performance.

How would you solve this (with a manager or without)?

This seems like a common problem to me, when using animated characters that are built from sprites. How is this usually done?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: flip
« Reply #18 on: November 28, 2013, 06:54:02 pm »
If you're already animating the character and mecanim is already setting the z values, I can't see what harm another pass of changing the z values is going to do. How much of a hit this is going to be depends on how your hierarchy is set up. If its largely flat with a few nested children it'll cost a lot less to update than a very deeply nested hierarchy where all children. Alternatively if you are on Unity 4.3, use the order in layer property instead of z to sort your sprites.

Since you already have code to flip the z, try calling it every frame and see how much of a hit it is and if it is a problem to start with?

I don't know if there is a way to get mecanim not to stomp your z values - that would probably be one for the unity answers forum.

Orion

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: flip
« Reply #19 on: November 28, 2013, 06:59:04 pm »
You are right. It's worth a shot. Although my code for flipping just negates the z position, so calling it repeatedly will mess things up. But I'm sure I can create some sort of simple system that just keeps setting every transform to the correct z value.