Search Unity

Trying to create a folding closet door in Unity

Discussion in 'Physics' started by Fauxtrot, Aug 19, 2015.

  1. Fauxtrot

    Fauxtrot

    Joined:
    Aug 19, 2015
    Posts:
    3
    I went and downloaded a Blender model for a closet door that features door folding - when you pull open a door and it folds in half as it opens. The model in Blender contains some armatures for pushing and pulling open the doors while in Pose mode. It's pretty neat, but trying to re-create this feature in Unity has left me pretty lost. I tried fiddling with the model in Unity via changing the rig settings in the model import settings (sadly, I have very little knowledge in rigging so I'm not quite sure what I'm doing), attempting to attach the folding doors as rigidbody objects with a hinge joint (no dice), creating an animation with the folding doors (which I also have no experience in and would create a result that wouldn't be what I'm looking for, details below), and some variants of those attempts.

    My desired end result would be to have a working closet door that would behave similarly to a single rigidbody door with a hinge joint. I have a current system for doors that behaves similarly to the grabbing system in popular survival horror games like Amnesia: The Dark Descent. It needs tweaking, but gets the main idea across for the time being.
    private IEnumerator DoorGrab() {
    if(!isLocked) {
    while(!Input.GetKeyUp(KeyCode.Mouse0)) {
    rigidbody.AddForce((player.transform.position - playerPosOff) * 500); //500 feels about right.

    playerPosOff = Vector3.Slerp(playerPosOff, player.transform.position, 0.5f);

    yield return null;
    }
    }
    }
    I wouldn't be asking a forum unless I was very lost on a problem, which I am right now. In what way could I start working to achieve this result? Alternatively, would it be easier to just trigger a door-opening animation when I left-click on the closet door (which I really want to avoid)?

    EDIT: A picture preview of the closet model and door system in context. The closet is just a static, non-interactive model right now.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    I kinda made a solution. The idea is to use hinge joints on the door parts in conjunction with a script that moves the hinge.

    I've attached a unity package with the scene and a script. It should be self-explanatory, but the idea is this:

    for each door (that is, one of the two moving doors that make up the whole closet door):
    1: Put two hinge joints on both of the door pieces. Connect one of the joints to the central hinge of the door, and the other to that piece's side of the door. This will make both of the door pieces move to stay in a line between the hinge and the side.
    2: Create a script that defines a circle around each side of the door, and positions the hinge in the intersection of those two circles.
    3: Move the hinge, and see the magic happen.


    Hope that helps, feel free to ask questions. I shamelessly grabbed the circle intersection code from stack overflow, so the variables there are poorly named, and I have no idea what's going on in that method. Trig stuff is my best bet.
     

    Attached Files:

  3. foosart

    foosart

    Joined:
    Jun 6, 2012
    Posts:
    66
    I'm looking for this exact solution, for decorative Japanese style folding room divider. @baset I tried your example package but it does not work. When I play it in Unity the red handle is not selectable.

    Thank you.
     
  4. MadLuko

    MadLuko

    Joined:
    Feb 6, 2019
    Posts:
    4
    @baset this is great. @foosart You need to grab the handle in the scene window whilst in play mode.
     
  5. MadLuko

    MadLuko

    Joined:
    Feb 6, 2019
    Posts:
    4
    @baset I need to be able to do this with 4 panels. Any ideas?
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    Don't necro years old threads. Also don't @ the wrong user. "baset was last seen: Sep 12, 2014"

    I have no idea what OP was asking for, or what solution I gave them. I replied over three and a half years ago. So Idk. Create a new thread and explain your problem,

    Also... this level of forum incompetence makes it seem like you're probably also too incompetent at other things to be able to understand any help you'd be given anyway.
     
  7. MadLuko

    MadLuko

    Joined:
    Feb 6, 2019
    Posts:
    4
    @Baste thanks for your swift reply and patronism.