- Home /
Other
multiplying door problem!!
hello , i made a door ( in blender) and i animated in unity i done a script and it work perfectly but when i want to duplicate it the second door moves position where my first door is. and i don't know if its the methode or the script problem. here the script in case.
var Target : GameObject;
function Start () {
}
function OnTriggerEnter ( player : Collider ){
if ( player.tag == "Player"){
GameObject.Find( "door").animation.Play ( "openD" );
}
}
function OnTriggerExit ( player : Collider ){
if ( player.tag == "Player"){
yield WaitForSeconds (3);
GameObject.Find( "door").animation.Play ( "closeD" );
}
}
Is the above script intended to be on the door? There's no need at all to use GameObject.Find.
Answer by seb-lopez · Aug 03, 2014 at 12:37 PM
well at the end i made a model in blender made it own animation and it worked better. thank you anyways.
Answer by dsada · Jun 07, 2014 at 02:28 PM
my best guess is you have the same problem that this guy had:
http://forum.unity3d.com/threads/animation-position-jump.26943/
EDIT: I edited the link, because that not that i wanted to link
hmm didn't help me , but what i don't understand why it won't animate in a fix position. i was thinking to change the script , ins$$anonymous$$d of having animation, it when it enter's the trigger the gameobject will go up with scripting but i don't know how to do it besides animation =(
The reason is when you create an animation inside unity you actually give its position,rotation,scale in every frame. So even if you move it away, the first frame will move the object back to the place that you added while creatin the animation.
The biggest problem, that you cant say to this position to be relative like: let the position be current position + 5 unit.
But a great workaround is to make the object (in your case the door) as a child of an other gameobject and the position,rotation,scale will be relative to the parent object.
After this do NOT move the door to the desired position, but move the parent object to a position where you can see the door is at the right position. But you need think about your animation. If your door hasn't got the same transform datas as your animation's first frame it is going to jump there.
I am still pretty sure this is your problem, maybe you didnt understand the linked post enough. So please try it one more time, I am sure this gonna fix it :)
ok so i should make a empty game object on the moving door part and animate it? ( thanks for explain my problem =) )
I recommend to redo your animation. I mean first make you object's parent an empty gameobject then start doing your animation and it should be fine. $$anonymous$$ake sure your objects position is 0,0,0 in the first frame. And if you want to move your door, move the parent object ins$$anonymous$$d of the door
Follow this Question
Related Questions
Trouble with Animation 0 Answers
Trigger door animation with external trigger 1 Answer
Character goes into unwanted state. 0 Answers