- Home /
Custom Weapon Animation
So I created a custom weapon inside of Lightwave, assigned bones, weight maps, animated it, saved the scene, and exported it as a .FBX file. I bring it into Unity and it appears to work fine. If I set the animation to loop and drag the weapon onto the floor of my level and let it go it plays great. So now I attach it to my character and add some code so the animation plays on left mouse click. When I click however, the animation plays but all the pieces of my weapon get thrown out of whack. I was wondering if anyone has experienced this or may know the issue. Below is a link to a video showing the problem as well as the code being used. If more information is needed please let me know and I will try to give as many details as possible.
Video Link: http://www.youtube.com/watch?v=byGtZxerKlU
Have you tried to attach the boxing box as a child of the player. Then just try it with an if(Input) to see if it goes fine. I mean without scripting.
Answer by Grady · Jun 15, 2012 at 06:38 AM
Hey! Just sort of an elaboration to @fafase. What I would do, is make your boxing glove box a child object of the camera. Once it is, position it so that it looks like it's in the right position from the first person view. Then just make sure that you're animation is attached to the box game object, and make sure the animation is not on loop.
Then just add a simple script to it like this:
function Update(){
if(Input.GetButtonDown("Fire1"){
animation.Play("yourAnimation");
}
}
Then just change yourAnimation
to whatever the name of the animation for the box is! Once again, remember to make sure you have the animation attached to the box!
I hope this solves your problem, as I'm sure it's that script you already have on there that is causing the trouble for you!
If this doesn't help, then post back and I will see what I can do!
-Grady
I parented the Boxing Glove Box to the camera and added the script to the boxing glove with the code you gave. It still has all the pieces of my weapon flipping out in different directions.
I would get back in the animation window and start it again.
It's working now. It was importing wrong because I didn't set up the model in it's normal relaxed state inside of $$anonymous$$odeler, I just modeled it and set it up inside Layout. What you need to do is set up inside modeler as it will look and orient on the 1st frame f animation. Then in Layout animate from that point forward. Also I created a Null object and parented my model and rig to that. Not sure if that helped or not but it didn't hurt. Thank you so much for your help!
Answer by VictoryX · Jun 15, 2012 at 10:02 AM
I parented the Boxing Glove Box to the camera and added the script to the boxing glove with the code you gave. It still has all the pieces of my weapon flipping out in different directions.