Problem with door script

Hi,
I have a problem with a door script i am making, to activate the door the player has to be pressing e and be within 3 units of the door, it then activates a script, the script is attatched to the door but the door opens no matter how far away i am, and when i change it to 1 unit it dosent workat all and when i attatch the door script to the player object then when the animation is played the player object moves instead of the door
Script:

function Update () {

var up = transform.TransformDirection(Vector3.forward);

if(Physics.Raycast(transform.position,up,2)&Input.GetKeyDown(“e”)){

animation.Play(“DoorAnim”);

}

}
Im working in JavaScript

Maybe your raycast hits something that is not the player. You should create a raycasthit object to check whether ist really the player that was hit. Also its much more efficient to only do the raycast when e is being pressed rather than doing it every frame.

At the moment the only other gameObjects in the scene are the floor the player and the door, the door dosent have a frame

You could use a bool and collider set to trigger, which would be less computationally expensive:

public var closeEnough:bool = false;

function OnCollisionEnter(other:Collider){
closeEnough = true;
}
function OnCollisionExit(other:Collider){
closeEnough = false;
}

function Update(){
if(closeEnough  Input.GetKey("e"){
animation.Play("DoorAnim");
}

You could use a coroutine instead of update and save even more.

Otherwise, if you put the raycast on the player, you would just call a function on the door from the hit.collider.gameObject.GetComponent(script).