Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Invisible walls as in Project zomboid

Discussion in 'General Discussion' started by miragercm, Dec 17, 2021.

  1. miragercm

    miragercm

    Joined:
    Dec 14, 2021
    Posts:
    9
    Hello to all.
    How can i do this in Unity?


    I found this tutorial, maybe this is what I need.
    However, I did not understand what should be in "OnTriggerEnter"? o_O
    How can I make my character be the trigger?

    Also, should I make each floor from separate walls or can I divide the entire wall of the house into different parts?
    Thanks
     
  2. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    I have not watched the video, but I can almost guarantee the answer you are looking for is use as many colliders as you need.

    In my FPS I have a collider for movement, a collider for enemy attacks, a collider for item interactions, and a ray for footing.

    It’s really okay to load it up so long as you are making sure to limit what they interact with in your project settings.

    And as for triggers, think of them as being solely for logic such as switches or toggles for enemy AI.

    If it’s physics based, don’t do a trigger.

    As for invisible walls, just do a cube then delete the mesh components.

    Maybe add a physics material with 0 bounce and 0 friction.
     
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,615
    There are a lot of different objects that might register OnTriggerEnter with a trigger collider. If you want to write code that only responds to a specific object (like your player character) then you just have to identify the object. One easy way is to use tags. You could give the player object a tag called "Player". Then in your OnTriggerEnter you can use CompareTag to see if the object's tag matches. There is an example in the manual:
    https://docs.unity3d.com/ScriptReference/Component.CompareTag.html
     
  4. miragercm

    miragercm

    Joined:
    Dec 14, 2021
    Posts:
    9
    First of all, thanks a lot for your reply and Info!

    Honestly, I took the script from this video (well, or another video on his channel ...) and I managed to use it. Unfortunately, I did not understand why I could not write
    Code (CSharp):
    1. If (gameObject.name == "Character")
    as an input trigger, but I wrote it like this and everything began to work:
    Code (CSharp):
    1. If (other.tag == "Player")
    Now i have this task:
    1) Make it so that when I go up to the second floor, the lower floor becomes visible along with the ceiling, and all the upper floors are still transparent. Well, I think you understand my idea.

    2) Also, I would like not the whole country to disappear entirely, but a small strip remained at the bottom and also in the corners. I'll attach a picture.

    3) The script does not work correctly, because I can hit the wall and one part of the character climbs over the texture of the wall and the trigger is falsely triggered. How can i fix this?

    And of course I am looking for the most optimal solutions. After all, I want to make a whole city, not a couple of three houses️

    II appreciate any help and I will be glad if you can tell me something about at least one of these points.
    Have a nice time!
     

    Attached Files:

  5. miragercm

    miragercm

    Joined:
    Dec 14, 2021
    Posts:
    9
    Thanks, unfortunately I saw the answer only later:D

    In principle, I already understood a little about triggers. Now I need to solve the problems that I wrote about above.

    Any help would be welcome.:)
     
  6. Nicwil92

    Nicwil92

    Joined:
    Dec 19, 2021
    Posts:
    1
    I'd like to review this post with a new answer and another question related to this topic.

    1. "See-trough Shader" from Unity asset store
    Check out this paid asset on the asset store, it might provide a flexible and easy solution to this problem.
    https://assetstore.unity.com/packages/tools/particles-effects/see-through-shader-193955

    2. Lighting question
    As seen in the tutorial video, upon deactivating the gameobjects, the room becomes sun-lit and behaves like an outdoor area (from a lighting perspective). This is a no-go for me, as this takes away the feeling of being in an indoor area.
    How can a game object be cut/deactivated or excluded from the player camera, while still blocking light?