- Home /
Closing sliding door Raycasting
Hello,
Currently we have two sliding doors which slide apart (like a convenience store). The doors open using Raycasting, but they do not close. How do we get the doors to close?
Also, one door slides open then the other door slides open when the FPS gets close. How do we get both doors to slide open at the same time?
Below is the code we use to open our doors with FPS controller.
var rayCastLength = 5;
function Update()
{
var hit : RaycastHit;
//check if we're colliding
if(Physics. Raycast(transform.position, transform.forward, hit, rayCastLength))
{
//...with a door_open
if(hit.collider.gameObject.tag =="door")
{
// open the door!
hit.collider.gameObject.animation.Play("door_open");
}
}
}
Answer by Valdemars Magone · Apr 18, 2011 at 04:56 PM
It would be a lot easier to use iTween, then you don't have to import any animation, just write the sliding in your script.
I have it in my game :
var hit : RaycastHit;
if(Physics.Raycast(transform.position,transform.forward,hit,rayCastLength))
{
if (hit.collider.gameObject.tag =="door1")
{
openDoor1();
}
function openDoor1(){
iTween.MoveTo(door1, {"x" : 16.2,"time" : 3, "transition" : "spring"});
yield WaitForSeconds (3);
iTween.MoveTo(door1, {"x" : 19.5, "time" : 3, "transition" : "spring"});
}
Just take a look at iTween, BTW, it' s free.
Your answer
Follow this Question
Related Questions
open and close a door with a keypress 6 Answers
Open & Close a simple door animation with sound and door states 1 Answer
Openable Door. Please help me with this!! 0 Answers
open and close door 0 Answers
Simple Script - and no result 2 Answers