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
0
Question by Renidus · Jun 12, 2013 at 03:05 AM · camera2dshaderplanelayer

How to simulate 2D layers in Unity

So, I've been experimenting with making a 2D game in Unity.

Nothing unusual (I think)- fixed camera angle + Z-depth to simulate parallaxing.

The problem I'm having is that often I want to have several sprites on the same layer, but without them clipping into each other or having z-fighting issues if they move away from the center of the camera's view.

I place my sprites as transparency-enabled materials on vertical 2D planes. They're pretty small textures, but I often use a lot of them- for example, for a single character, I sometimes have upwards of 8 planes to represent the character's arms, legs, and face.

The first thing that came to mind was to solve it by adding a very small difference in the Z axis to each semitransparent plane to simulate "layers" and determine which one draws on top of the other, but this still seems to have issues depending on where the objects are in the camera's view. Shortening the camera clipping helps but doesn't solve the problem entirely.

Is there an elegant way to solve the problem? Is it possible to have multiple semitransparent planes in the same Z position and define a some kind of Z-sorting to determine what should be drawn in front?

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

2 Replies

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

Answer by Fattie · Jun 12, 2013 at 07:17 AM

Unity I bet is now probably the biggest platform for 2D games.

"The problem I'm having is that often I want to have several sprites on the same layer, but without them clipping into each other or having z-fighting issues if they move away from the center of the camera's view."

I think you have two problesm

(1) To be clear are you using an orthographic camera ?! Generally you must do this for 2.5D games

(2) "The first thing that came to mind was to solve it by adding a very small difference in the Z axis to each semitransparent plane to simulate "layers" and determine which one draws on top of the other" ..

you are a natural game engineer, because that is exactly what you do

Say you have a layer at 10 (perhaps the clouds), and a layer at 8 ("enemies") and a layer at 5 ("bullets", say).

In fact, depending on the nature of the game, let's look at the layer at 5. What you normally have to do is "microstack" that layer (again depending on the game etc etc), so each one has a slightly different Z.

If you read my boring novel about pools here ... long post on pools, please vote it up because I need moar points! ...in fact sometimes at the pool level you will move them around in micro-layers. (it's a bit of a nuisance really.)

So, you precisely hit the nail on the head.

Now when you say this "but this still seems to have issues depending on where the objects are in the camera's view" ... that's just wrong. You have some sort of bug or problem.

Again you are using orthographic, right? Even if not, you just have some woe if that is not working. That is a separate question, I encourage you to post a new question with images etc. if you are still having that problem.

Incidentally it's almost impossible to bother doing 2D in unity without 2DToolkit, it's great. It is very widely used. Before wasting a moment on 2D development, get 2DToolkit (and all its competitors) and have a real experimentation with them and decide which one to use going forward.

Hope it helps

Comment
Add comment · Show 2 · 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 Renidus · Jun 12, 2013 at 01:39 PM 0
Share

Thanks! This actually helps a lot. $$anonymous$$y camera was -not- set to Orthographic, as a matter of fact, and this seems to have been the root cause for most of my problems. :)

$$anonymous$$any thanks again! Checking out 2DToolkit now :)

avatar image Fattie · Jun 12, 2013 at 01:51 PM 0
Share

Funny, I once answered another very similar question to this but I can't find it now

http://answers.unity3d.com/questions/435408/object-shown-on-top-of-another-while-it-shoulndt-b.html

Notice it's a common issue that comes up, on this one search down to the guys talking about "0.1" and so on

http://answers.unity3d.com/questions/311570/bullets-spawn-behind-the-craft.html

avatar image
0

Answer by MaT227 · Jun 12, 2013 at 06:19 AM

I don't know if it will solve you problem but you can look at this post.

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

16 People are following this question.

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

Related Questions

2d games: Camera settings? 3 Answers

2D and distortion shader 1 Answer

Is there a way to change the order of the "Layers" Tab? 0 Answers

Wrong Depth texture being passed into the shader. 0 Answers

2d Shader: How to show camera view on a sprite? 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