How to play an animation relative to an object's position?

I’m making a small horror game and I’ve run into some troubles while trying to get a sliding door to work. Basically, the way the door works is the player enters a trigger and when the ‘E’ key is pressed, an animation plays which simply slides the door to the left and back. Here’s the code for the door(JavaScript):

#pragma strict

private var intrigger : boolean;

function OnTriggerEnter (other : Collider) {

	if (other.gameObject.tag == "Player") 
	{
	intrigger = true;
	}
}

function OnTriggerExit (other : Collider) {

	if (other.gameObject.tag == "Player") 
	{
	intrigger = false;
	}
	
}

function Update () {

	if(intrigger == true && Input.GetKeyDown("e"))
	{

		//currentTransform.parent.
		animation.Play("DoorOpen");

	}
	
}

Now here’s my problem: The door works fine and animates fine until I duplicate it and move it else where. Then when the animation triggers, the door snaps back to the position of the original door. Before anyone says it, yes, I have attached the door body to an empty game object and animated the empty object. I’m really not sure what to do as I’ve tried everything that I’ve seen so far.

Thanks in advance to anyone who can help.

It seems that your animation contains a curve which animates the position of the door. In this case, this curve will change the position of any game object which have this animation as a component, regardless to its original position.

To solve this problem:

  • If you don’t need to animate the position of the door, then delete the position curve and duplicate the door. This way, the new door will still in its own position after animating.

  • If you need that the animation changes the position of the door, then you should make a copy of the animation. In the new copy of the animation, create a new position curve for the new door.