Revolving door

I’m new to unity, and am trying to figure a way to create a revolving door, so that when my player runs into it, the door will rotate 90 degrees as the player goes forward.
I tried creating a hinge joint on the object, but when my player runs into one of the walls on the revolving door it spins on a bunch of axes. I was wonder wether the best way to do this would be using a script with OnCollisionEnter or OnTrigger or something else.

Thanks

The OnTriggerEnter should work great. If you want to make it go open from a distance, you could make an if statement with a [Vector3.Distance][1] and trigger it when the distance is lower than the distance you want.

To rotate, you can simply use [Quaternion.RotateTowards][2]:

For example:

public float speed = 5, distance = 5;
public Vector3 rotateAngle = New Vector3(0, 90, 0);

void Update() {
    if(Vector3.Distance(player.transform.position, transform.position) < distance)
    {
        transform.rotation = Quaternion.RotateTowards(transform.rotation, transform.rotation + rotateAngle, speed * Time.DeltaTime);
    }
}

Comment if there’s an error, i didn’t check it :slight_smile:
[1]: Unity - Scripting API: Vector3.Distance
[2]: Unity - Scripting API: Quaternion.RotateTowards