Forum rules - please read before posting.

Order in Layer and 3D Character

edited September 2017 in Technical Q&A
In 2D environment + Unity 2D Moving I am trying to fix the Order in Layer issue of a 3D character.
At the moment I'm experimenting with z-position.
I place the 3D character at z = -1 and therefore, according to the needs of the scene, I have to move the sprites in front of the character altering their z.
In the case of the attached scene, the character must disappear behind the wall.

image

So I placed a Trigger in front of the door by configuring it as visible in the image because it is the only solution I've been able to find.
I position the wall sprite in the scene with z = -3 (in the image z = -4.18 to see it better) and I make it unseen.
When the trigger is activated with the character passage check if the sprite is visible and then makes it invisible and vice versa.
This sequence is, however, unreliable because if the character affect the trigger without crossing it, the sprite may become inadvertently visible.
Initially I was thinking of placing the sprite overlying on the background with z = 0 and editing its z through Action List called by the Trigger but I could not find the right option. It would seem that the object should be Moveable but I'm not sure it works in 2D environment.
Would it be possible to change the values of Transform -> Position (z in my case) of objects at RunTime?
Another possibility, given that the environment is only [x, y], could be a script that non-stop checks the character y and moves / makes visible all the sprites in the scene with their y less than the character y. In this case, I'm still get to know with AC and Unity, where would the script be inserted? 

Comments

  • edited September 2017
    I believe that when sprites are involved, the display order is only reliable when using the "Order In Layer" etc options provided in the Sprite Renderer Inspector.  The z-positions should be kept the same.

    Similar options do not exist in the Mesh Renderer Inspector, but they do exist internally - and the Sorting Map affects them.  However, a custom shader must then be used to properly make use of those properties to have models and sprites display correctly together.  Search the Unity forums - it's a topic that's been covered a few times IIRC.

    Whether or not you use the Sorting Map for that purpose, however, you can still use it to update the Z position.  A custom script could feasibly just read the player's "Order In Layer" value every frame and convert it to a positional change.  The Sorting Map is already making changes every frame based on player position, so if you do want to go down the "z position altering" route it's easier to just let the SM do the work and just read it's output:

    float zPos = (float) myPlayerMeshRenderer.sortingOrder;
    playerPosition = new Vector3 (playerPosition.x, playerPosition.y, zPos);

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.