- Home /
Layer Sprites Based on Y axis
I am making a top down rpg and too create depth I need to having sprites near the bottom of the screen appear on top of higher up sprites.
My current workaround involves changing each objects z axis whenever they interact with one another
void OnTriggerStay2D(Collider2D other){
float depth = transform.position.z;
if(other.transform.position.y > transform.position.y)
depth = other.transform.position.z - 1;
else if (other.transform.position.y < transform.position.y)
depth = other.transform.position.z + 1;
transform.position = new Vector3(transform.position.x, transform.position.y, depth);
}
but this isn't ideal because characters of different heights may still pass over each other and it can get unpredictable once there are more than two objects involved.
Any suggestions on how to do this? Its likely that I'm just missing a very obvious camera option or something like. All help is appreciated!
Answer by charlietheGfish · Jul 15, 2015 at 10:53 AM
This forum seems to answer this pretty well - http://forum.unity3d.com/threads/dynamic-draw-order-or-2d-z-buffer.220231/
Your answer
Follow this Question
Related Questions
Sprite Failing to Load into Scene 0 Answers
How to duplicate several layers in a tilemap?,How to duplicate layered tilemaps? 0 Answers
How to bring empty game object in front of other Panels? 1 Answer
Layering issue with sprites 1 Answer
how to dynamically change 2d sprite offset when drawing? 1 Answer