- Home /
The question is answered, right answer was accepted
Prefab animation problem
Hi everyone !
I'm not sure if it's the right place to ask my question (I hesitated with a Maya forum), but I'll try ...
I have a problem with a prefab made with a maya model. When I try to instantiate it in a specific position and animate it, it moves instantly to origin and play the animation. But if I delete the animation line, the game object stays where it should be. I don't have this problem with an other prefab. The code is the same, only the maya model is different. I have a skeleton in the second model, contrary t the first one, I don't know if it's the problem ...
Answer by KiraSensei · Aug 03, 2012 at 04:01 PM
I found my problem : the issue was the skeleton ! I added one joint (yes, only one, very useful ...) to my model, moved the animation from my geometry to my joint and here it works ! An other problem now is that I need to attach a box collider to my prefabs, and if there is at least a joint, the box collider does not follow the animation. I don't know why, and for the moment and in my game this is not important. If someone has an idea why there are these weird problems, let me know :)
Answer by MKlegoman357 · Aug 03, 2012 at 12:30 AM
You should make an empty game object that should be parent of your made and animated object. This empty game object must have all scripts that is made to your game object.
To run an animation of your game object you have to make a variable that is type of GameObject and would be your game object. use this (javascript):
var myObject : GameObject; //your game object that has animation
var myAnimation : String; //your animation name
//when you want to run animation do this:
myObject.animation.Play(myAnimation);
this is working even when you are changing the transform of the empty game object.
I already have done that, this is not the problem. $$anonymous$$y problem is that I have two prefabs from maya, and a different behavior when I try to instantiate them (by code), and I don't understand why. The code is exactly the same, but not the prefabs ...
try to reimport the object or remake animation. I think there can be a problem when you change the scale of an object. $$anonymous$$aybe you could try to reemport the object(don't change scale) make an empty game object that would be parent of your game object and then rescale empty game object.
I'll try to reimport it or recreate the animation, but I don't really think it will be better. I already have an empty object that contains this game object, it contains also other gameobjects (like the other one which has no problem with its animation ...), so i can't rescale the parent.
Answer by MKlegoman357 · Aug 03, 2012 at 12:30 AM
You should make an empty game object that should be parent of your made and animated object. This empty game object must have all scripts that is made to your game object.
To run an animation of your game object you have to make a variable that is type of GameObject and would be your game object. use this (javascript):
var myObject : GameObject; //your game object that has animation
var myAnimation : String; //your animation name
//when you want to run animation do this:
myObject.animation.