Door goes through character

Hello.

I made a code that runs an animation for the door to turn 90 degrees in y axis
but when i open it, it just goes through my character (First Person Controller)
Is there anyway i can stop the animation if it hits the character or just goes back to its normal open/closed state?

here’s my code.

using UnityEngine;
using System.Collections;

public class InputHandler : MonoBehaviour {


	int length = 3;
	// Update is called once per frame
	void Update () 
	{
		if(Input.GetMouseButton(0)){

			RaycastHit hit;

			if(Physics.Raycast(Camera.main.transform.position,Camera.main.transform.forward, out hit, length))
			{
				InteractiveObject obj = hit.collider.GetComponent<InteractiveObject>();
				if(obj)
				{
					obj.TriggerInteraction();
				}
			}
		}
	}
}


//Second script file

using UnityEngine;
using System.Collections;

public class InteractiveObject : MonoBehaviour {
	
	bool DoorState;




	void start ()
	{
		DoorState = false;
	}
	public void TriggerInteraction()
	{
		if(!animation.isPlaying)
		{
		switch (DoorState)
		{
		case false:
			
			animation.Play("Open");
			DoorState = true;
			break;
		case true:
			animation.Play ("Close");
			DoorState = false;
			break;
			
		}
		}
		
	}
	
	
}

public class InteractiveObject : MonoBehaviour {

void OnCollisionEnter(Collision c) {
animtion.Stop();
}
}

…but there qre two questions:

  1. does your door have collider attached? if it doesnot - its a trouble…
  2. if it does - what is it attached to? does it turn during animation? if it doesnot - its a trouble…
  3. Maybe you would not to use animations here, but just rotate door via Rotation.Slerp? In this case you are free to add collider to door leaf, make a DoorLeaf script that will detect a collider’s collision and will report to Door script, and that Door script will stop rotation doorLeaf.

… ghree questions actually ;))