Forum rules - please read before posting.

How to make doors open away from the player in 3D

I'm working on a first-person game and I've got doors that open, close, lock, etc. All that is working great. I'm wondering if there is a way, through adventure creator, to make doors always open away from the player? Right now I have open and close animation which pivot the door on one corner when activated. It's great when they swing outward but I'm realizing how clunky it can be when the door swings toward the player, either bumping the character controller or clipping through it. I think I'd sacrifice some realism to have a smoother gameplay experience. I'm guessing this might require a script to determine which side of the door the player is on and then play the appropriate animation. But I'm not really sure how to approach this. Any help is much appreciated.

Comments

  • Sorry if this is more of a Unity question. I just thought that since my door logic is based on an AC action list, it would be great if there were a solution that somehow integrated with that.

  • If you're currently playing the "open" animation by name, switch to a Trigger parameter in your Animator so that you can then rely on an additional "Side on" bool parameter that - combined with the Trigger - causes one of two door-opening animations to play.

    Test this out by checking/unchecking the bool manually in the Animator window, and it's then just a case of setting this value in-game.

    In AC alone, this could feasibly be done by having Triggers on each side of the door that both run Object: Animate Actions to set this bool to True/False accordingly.

    Otherwise, you could rely on a custom script that updates the value automatically just as the Interaction is run. This can be done by hooking into the OnBeginActionList custom event:

    using UnityEngine;
    using AC;
    
    public class SetDoorSide : MonoBehaviour
    {
    
        public Interaction interaction;
        public Animator animator;
        public Transform door;
    
        private void OnEnable () { EventManager.OnBeginActionList += OnBeginActionList; }
        private void OnDisable () { EventManager.OnBeginActionList -= OnBeginActionList; }
    
    
        private void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
        {
            if (actionList == interaction)
            {
                float dotProduct = Vector3.Dot (door.forward, (door.position - KickStarter.player.transform.position).normalized);
                bool sideOn = dotProduct >= 0f;
                animator.SetBool ("SideOn", sideOn);
            }
        }
    
    }
    
  • Thanks so much. You are a legend. I ended up doing it with triggers attached to either side the door which toggle the bool. I couldn't be happier with how the doors are working now.
    I guess I better get off my lazy butt and go make a five star review for AC.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.