• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Leonstar0 · Feb 24, 2017 at 09:49 AM · 2d2d animationcoinsz-fighting

2D Z-Fighting - I have no idea how to fix this, someone please help!

alt text

Alright so, as the title says, this is an issue with 2D Z-Fighting, specifically, the "coins" that I am using.

What is the specific details? And what in the heck is going on in the image above? Well here is my understanding!

The Coins consist of two objects, the coin 'base', which contains the inner part of the coin, and the coin 'border', which rotates around the coin base. It achieves this rotation animation via the inbuilt Unity Animation thingo, the z-rotation property is linearly animated between 0 and 360 degrees, with loop pose turned on. This makes the animation real smooth like.

Normally, I wouldn't care if two coins were Z-fighting, as long as they were always fully layered... however that was back when coins were one object. Now the border of one coin can render in front of another coin.

Now, if you'll note, the above statement provides a solution: just create a sprite-based animation externally, then the spinning border and base will be considered as one render, giving me the behavior I had before. But man! Is it tricky to get a seamless rotation externally, without it looking a bit jerky! it looks much better when rendered internally anyway! (Also it's harder to animate it externally, as free animation tools... sigh... I mean, I have been using OpenToonz which can do what I want, but it adds a weird yellow outline to the border-part of the coin... but that's a whole different issue.)

Another solution I came up with would be to assign a different layer order to each coin and border pair, or well... two layers orders to insure the border renders in front of each instance of a coin. But I don't feel comfortable doing it like that, it seems like it might cause a lot of overhead... you know?

Ah well, I'm just wondering what would be the best way to tackle this situation, any insight would be greatly appreciated!

unknown-copy.png (7.1 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThisGuyThatsHere · Feb 24, 2017 at 02:31 PM 0
Share

Well, that's still beta, but didn't Unity 5.6b introduce something like sorting order order? You can always look for other solution, but as far as I read changelog there was something that I understood as you can sort sprites in their "local space" and then sort combinations in the old way.

You just a thought

avatar image Leonstar0 ThisGuyThatsHere · Feb 25, 2017 at 03:54 AM 0
Share

Yes. By "layer order", I meant "order in the layer" : P. Or well, sorting orders in layers... Sorry, it made sense in my head, you know how these things go : P.

Thank you tho!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by hrgchris · Feb 24, 2017 at 12:47 PM

I think you'll ultimately have to specify the order in layer as you suggest. You should only have to do that once though when you create the coin. In theory you could try and keep track of what layers are used, but I would hazard that you'll do just as well choosing a random order-in-layer each time you spawn one.

i.e. on spawning a coin:

  • pick a random order-in-layer with something like mylayer = Random.Range(0,1000)

  • iterate over all the sprite renderers in your coin and set their order in layer accordingly

You can build on that solution by reserving multiple slots in the layer for a coin or changing the range of layers you use).

  • mylayer = Random.Range(0,1000)*10 + 100 //gives each coin 10 order-in-layer slots to play with, starting with layer 100

It won't be perfect, but it'll be nearly perfect and that's generally what you're after:, with these things :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Leonstar0 · Feb 25, 2017 at 03:51 AM 0
Share

Ah... Hmm... that could work!

I'm just wondering if all those extra layers would add significant overhead, but I suppose that won't be too hard to test for. Thanks!

Heheheh... I almost didn't fully understand your answer as I forgot the "start" function was called even for things that aren't instantiated during game play (the coins are placed around the map as well as being dropped by enemies), because I am very silly. But yeah :D, thanks again for the help!

I'll complain at you if it brings up bugs that are probably 100% my fault XD.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Transition between 2D animations with different frame width 0 Answers

Idle Animation Not Playing 1 Answer

2D Coins and Points 1 Answer

Animating a 2D character with this type of sprite 0 Answers

2D Animated tile synchronization 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges