Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Hide part of a sprite based on rotation?

Discussion in 'Editor & General Support' started by cliffy987, Aug 26, 2023.

  1. cliffy987

    cliffy987

    Joined:
    Feb 3, 2021
    Posts:
    13
    I am currently working on a 2D sprite-based project, and I was wondering if it's possible to have a sprite be partially hidden by another sprite based on it's rotation. To illustrate what I mean, I placed a black square sprite and a white square sprite on top of each other. Both have the exact same position (including the Z axis) and the exact same layer order. The black square is rotated 45 degrees along the Y axis. Ideally, the right half of the black square would be visible while the left half would be hidden (since the left half is rotated behind the white square), but the black square is still rendered completely in front of the white square. What is the best way to go about having the black square be partially hidden and partially visible?

    Squares viewed in 3D:
    upload_2023-8-26_10-3-45.png
    Squares viewed in 2D:
    upload_2023-8-26_10-4-13.png
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,718
    SpriteRenderers follow the 2D sorting rules for rendering:
    https://docs.unity3d.com/Manual/2DSorting.html

    They notably do NOT follow physical obstruction.

    Use a quad mesh with a MeshRenderer instead of a SpriteRenderer if you want to get realistic physical obstruction like this.
     
    Kurt-Dekker likes this.
  3. cliffy987

    cliffy987

    Joined:
    Feb 3, 2021
    Posts:
    13
    Makes sense, thanks for the tip!