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

Object Advice for interactions and Collision

Discussion in '2D' started by scossgrove, Jan 27, 2020.

  1. scossgrove

    scossgrove

    Joined:
    Jan 6, 2016
    Posts:
    35
    Hi,

    I have a series of objects that I need to be able to click to interact with and also have the object "obstruct" movement.

    Example: A door. I need the player which has a 2d box colider on it not to be able to walk through the door. However I would like to be able to Click on the door to interact (open / close) it. When the door is open I need the door no to stop the player from walking through it.

    Example: A Chest: I need to player not to be able to walk through the chest. However I would like to be able to click on the chest to interact(open / close) it.

    For what I understand the object graph is something like this
    GameObject (Parent) (Tag: Clickable & Obstruction) (Layer: Foreground)
    - Interact which has a 2d Box Colider and is a trigger. (Tag: Interactable)
    - Obstruction which has a 2d Box colider and is not a trigger. (Tag: Obstruction)

    I figure i can disable the obstruction object to allow for movement through the object in the case of door.

    Is this correct? Or is there a better way of doing it?
     
  2. Wezai

    Wezai

    Joined:
    Dec 30, 2016
    Posts:
    74
    You are correct, I can't think of a better way to do it. You are keeping it simple which is good.