- Home /
Layer Mask Not working to open the door
So i created a layer mask so i can open the door when im close to it but it wont work. code compiles and everything though. I created a cube made it into a ray got rid of render on the cube so user cant see it and put it as the doorout : transform and the target is my game character FPS. heres my code
var target: Transform; var doorout: Transform; var area: int=100; var speedOpen: int=1000; var speedClose: int=-1000; var angleClose: int; var angleOpen: int;
function Update(){
var layermask =1 << 8;
var forward = (doorout.transform.TransformDirection(Vector3.forward));
if (Physics.Raycast(doorout.transform.position, doorout.transform.forward,area,layermask)){
if (transform.localEulerAngles.y < angleOpen){
if(Input.GetKey("e")){
print("unlocked");
transform.Rotate(Vector3.up*Time.deltaTime*speedOpen);
}
}
}
}
Answer by DaveA · Mar 09, 2011 at 02:31 AM
Unless you're really married to this approach, the standard way of doing it is using a proximity sensor. You make that by putting a collider (Box collider is nice) as the proximity volume, set that to Is Trigger, and use the OnCollisionEnter function to trigger your animation/sound/etc.
Your answer
Follow this Question
Related Questions
Why does Layer Masking for Raycasts only work on Layer 8? 1 Answer
Can't Make Raycast Ignore a Layer 3 Answers
Player can't block door 0 Answers
Raycast not working ? 1 Answer
Open door with key 2 Answers