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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Opening Doors When They Are Clicked Unity Reflect

Discussion in 'Unity Reflect' started by grimPatreon, Jul 28, 2020.

  1. grimPatreon


    May 19, 2020
    While editing the Unity Reflect prefab I've been running into a few problems. The goal is to have a door be touched by the user (Either by mouse on pc or touch on mobile) and animate open. Do you guys have any suggestions because I have been having a lot of trouble coming up with the logic. I am an intermediate Unity and C# developer.

    The logic that I've been thinking of goes something like this (keep in mind I don't know exactly how to code this it's just the thought process I've gone through. I was planning on just coding a for loop that goes through and stores all pieces of the Revit model that have door metadata from Revit. I would then have an if loop that checks if that door is in the loop. This check would happen every time the user clicked the screen. If it is in the loop I would rotate it by 90 degrees over a set period of time to make the animation smoother.

    Unity Version 2019.4.1f1
    Unity Reflect Version: 1.2.0

    Any thoughts or responses are greatly appreciated.

    Thank You!
  2. quintus_smit


    May 15, 2019
    I wouldn't run the loop ever time there is a click, that is unnecessary overhead, especially on mobile. I would rather have a script that runs through once and then add an "Open door" script to each object that has the door type in the metadata. That way it only needs to happen once.

    There are three problems I see with this, however:
    1) There is no event that tells Unity the model is done loading. If this is done with an imported model it is not a problem but if you are doing it with a streamed model the script should only run once everything is loaded. *see comment below
    2) How do you distinguish between swing and slide doors (maybe have a specific project property set up in the metadata?)
    2) How do you know where the pivot point is on each door (right hand or left hand)

    *Fred Moreau found a workaround where he counts the number of imported elements via a script and then compares it with the expected number in the package
  3. FredMoreau


    Unity Technologies

    May 27, 2019

    here's a video I made a while back, prior to joining Unity, as part of a training video series, touching on animating doors.

    There are many ways to achieve this, but you basically need three things:
    1. The animation of the door (can be done using Animator or Timeline)
    2. A triggering event (using a collider to handle clicks or proximity checks)
    3. A script to link the two
    The major issue atm, is that doors come as one mesh, you can't isolate the slam from the jamb.
  4. quintus_smit


    May 15, 2019
    of course you already had a tutorial on this..overachiever :)