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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Hide objects in front of player in isometric view

Discussion in 'General Graphics' started by XRay3, Aug 12, 2023.

  1. XRay3

    XRay3

    Joined:
    Aug 9, 2021
    Posts:
    5
    Hi,

    I've got a question about hiding objects in front of player using a static camera position like isometric view. I can not solve it by rotating and/or repositioning the camera. I'm pretty sure most people know games like Diablo, PoE etc.

    My current solution is as follows: designing prefabs (it's all modular) with box colliders as triggers on the ground. The box colliders are of course larger than the ground (let's say for a 1x1 ground the box collider is 3x2 - which excludes the 1x1 square outside the wall). When entering the box collider trigger the wall (or whatever) is removed/replaced. Seems to work for easy levels. But when I have larger rooms I need to span the box collider. Why? Let's assume the part is 1x1 and the room is 15x15 and the viewport can display the complete room. Leaving the 2 square (the original one within the prefab and the extra one) the wall will be visible again. So I'd need to span it across ~15 fields (or whatever my viewport can handle).

    Another solution would be to design the level so that wall on east/south sides are generally taller. But that would not work because if the player is outside a room it would still be visible (unless working with some kind of fog of war).

    So I'm looking for a decent solution. I could imagine that my solution is working nice on pre-designed areas like cities and houses or static dungeons. But I'd like to generate them randomly. So I'm looking for something that might be triggered by a camera-to-player calculation. How'd you solve this?

    Thanks for any input. I'd love to hear about different solutions :)
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    570
    This is what I would try, assuming I understood you correctly:
    - Add a component to every prefab which is responsible for hiding it. Write some code which
    -- projects the object's bounding box onto the screen using the projection matrix of the camera
    -- projects the player's bounding box onto the screen using the projection matrix of the camera
    -- hides the object if the two projected bounding boxes overlap in 2D AND the minimum screen-space z value of the object's bounding box is less than the maximum screen-space z value of the player's bounding box