- Home /
Problems with Sliding Door Animation (solved)
OK.. I'm suddenly getting problems with my door animations and I cant figure why.
Its a simple sliding door with 2 animations, one for open and one for close that activates as the player enters or leaves the 'trigger' area. I'm using a simple box collider that's been extended forwards and backwards around the door, together with a very simple script-
#pragma strict
//Puts Drag n Drop variable slot into Script
var doorClip : AnimationClip;
function Start () {
}
function OnTriggerEnter () {
animation.Play("SlideOpen3"); // Sets name of Animation clip to be played
}
function OnTriggerStay () {
}
function OnTriggerExit () {
animation.Play("SlideClosed3"); // Sets name of Animation clip to be played
}
Everything worked fine until I added extra doors and now the animations play while the player is within the collision box (animations just played on enter and exit before)
Each door has its own animation and own script
At first I had all the doors from a prefab and realised this was changing settings on the other doors so I separated them all into individual parts and reset the scripts and animations. Now that's when the problem started, I'm guessing I don't have a setting correct but cant see what is wrong?
An easier way for me to put it I think is that the close door animation is playing whenever I move within the collision box (not just on exiting the box as it should)
Thanks guys (or ladies)
"...all the doors from a prefab and realised this was changing settings on the other doors": prefabs don't cause that problem.
Spawned prefabs are individual. They get their own copy of all script variables, animation states... (if they didn't, they'd be useless.) Not using prefabs just makes the whole thing harder to change and test.
Tested with only two doors far apart, walking in/out of each?
Have tested with 1,2 and 3 doors but am still experiencing the same issues? What's most perplexing is that the problem has recently started where as it worked fine before ! I don't see why now even the smallest player movement while within the collision box is causing the animations to play?
Do a "regression." In a fresh scene, put the earliest version of the script, packed with Debug.Log
s and public vars. $$anonymous$$eep adding and testing until the error happens (or copy the scene and keep deleting until it goes away.)
You probably added something that seemed totally unrelated but broke it, put the script on the player by mistake... . At worst you'll have a rebuilt copy of your scene that now works, and can compare part by part to see what is different and broken in the original.
use the Activatetrigger.js that comes with unity, and see if it works, it is the most useful script on playing animation with trigger.
Answer by Digital-Phantom · Jul 05, 2013 at 01:01 PM
OK.. Im officially a noob...lol
The problem wasn't my script OR my animation, It was me ! I hadn't taken into consideration that using a prefab door would of course give me a prefab box collider. So the problem was actually the size of my box (no innuendo plz) The newer doors had the same size collider but the newer doorways were slightly bigger. This meant that the box collider only covered half the open door space and as the player walked through that space the door opened and closed as the collider touched the player. As the door opened fully the collider thought the player had left the doorway and played the door close anim and as soon as it did it hit the player again and opened... DOH !
Anyway thanks for all your replies guys, you actually helped me to solve another little issue I had too.
Thanks, again
Answering your own question is fine. But generally ins$$anonymous$$d of adding "solved" to the heading, just mark your answer as correct.
Also, note how more careful testing would have solved this. It takes a long time to learn not to quit after the first error, and ins$$anonymous$$d pretend you're writing a bug report. For almost anything it pays off to quickly test the stuff you "know" can't be the problem (like walking just up to the edge of the door.)
Your answer
Follow this Question
Related Questions
continuing an objects motion 1 Answer
When inside trigger, turn object on, when outside trigger, turn off 1 Answer
Can't call GetKey inside OnTriggerEnter? 2 Answers
How can I change animation with colliders? Using AR and Vuforia. 0 Answers
How to animate collider along with object for 2D game? 1 Answer