Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
3
Question by ZeWitcher · Jul 31, 2014 at 08:55 PM · spriterendering2.5d

Sprite Rendering Order Issue

Hello everyone,

Info

I am making a game similar to Don't Starve graphic-wise (Bill boarded 2D sprites inside a 3D environment) (Picture)

However I am using an orthographic camera as opposed to perspective with a 45 degree rotation around x-axis

The Problem

I noticed that some small sprites appear behind bigger ones even if they are positioned in front of them. After some research, I found out that Unity renders sprites based on the distance between the camera and CENTER of the sprite, therefore taller sprites will have centers that are closer to the camera. That is why this does not happen with objects that are the same height.

My theoretical solution is to tell Unity to use the BOTTOM of the sprites instead. That would work best but I do not know how to do that (if it is even possible). Any ideas?

Thank you in advance! :)

EDIT 1

Another way of saying "My theoretical solution is to tell Unity to use the BOTTOM of the sprites instead" is that I want sprites to be ordered only based on their z position.

Comment
Add comment · Show 1
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 JCouser · Oct 10, 2014 at 04:30 AM 0
Share

I'm currently in development of a billboarded 3d game as well and have ran into this issue several times. Was there any resolution or workaround that you've found?

4 Replies

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

Answer by darkerparker7 · Aug 29, 2018 at 02:48 AM

I've been banging my head against the wall with this problem for a long time and could not find a solution until today!

What I ended up doing to fix this exact problem was place everything under an empty GameObject container, and then simply rotate that while the camera stays in one place. I then added a custom transparency sort axis (x = 0, y = 0, z = 1). Works like a charm! I'm not sure what this means for moving about inside that container, but I don't think that is as big of an issue. Even with such a steep camera angle, still works fine.

Super excited about this! I am making a Realm of the Mad God demo which requires the same art style.

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 ZeWitcher · Dec 17, 2018 at 01:57 AM 0
Share

Thank you for your answer darkerparker7 :) I don't think the transparency sort axis was in the version of Unity I was using when I posted this question. It's great to see awesome features like that being added, and I really appreciate you telling me about it!

avatar image
1

Answer by contab009 · Jul 31, 2014 at 09:30 PM

Take a look at the Sorting Layers tutorial : http://unity3d.com/learn/tutorials/modules/beginner/2d/sorting-layers

Comment
Add comment · Show 3 · 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 ZeWitcher · Jul 31, 2014 at 10:13 PM 0
Share

I know about Sorting Layers. I want sprites to be ordered automatically based on their z position. $$anonymous$$y game is not set in a flat 2D world. I know I can make a script to order sprites every frame based on their z position but I want to know if there is a more efficient way of doing this. I also know that I can set the sortingOrder to the z position of sprite but that is my last resort.

avatar image Bill-Robinson ZeWitcher · May 18, 2017 at 08:31 PM 0
Share

Did you ever find a solution to this?

avatar image Shiro_Rin Bill-Robinson · May 19, 2017 at 01:44 AM 1
Share

I posted an answer that I've been using for awhile that should work.

avatar image
1

Answer by Shiro_Rin · May 19, 2017 at 01:44 AM

     public SpriteRenderer[] spriteLayers;
     public int[] spriteLayersSorting;
     void Start () {
         spriteLayersSorting = new int[spriteLayers.Length];
         for (int i = 0; i < spriteLayers.Length; i++) {
             spriteLayersSorting [i] = spriteLayers [i].sortingOrder;
         }
     }
     void FixedUpdate(){
         for (int i = 0; i < spriteLayers.Length; i++) {
             spriteLayers [i].sortingOrder = spriteLayersSorting [i] + ((int)-transform.position.z);
         }
     }
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 ZeWitcher · Dec 17, 2018 at 01:58 AM 0
Share

This is a good workaround!

avatar image
0

Answer by luoboa · Apr 15, 2020 at 12:33 AM

I was having a similar issue with wanting to sort based on z value.

If you go Project Settings > Graphics > Transparency Sort Mode and set it to Custom Axis and define the custom axis as 0, 0, 1 (so based on z values) it will sort based on z values.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Couple of Questions dealing with 2.5D 0 Answers

Terrain Handling For Performance Improvement in 2D Game 0 Answers

Background sprite does only render for half of the screen 0 Answers

Pixels artifacts after building project 0 Answers

Packing particles textures into one map 1 Answer


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