Animation Snapping to Origin

I have a quick question, I set up a basic first person shooter test, which consists of a character controller with a camera and gun attached. There’s one problem however, whenever an animation is played on the gun, the entire thing immediately snaps back to the origin of the Unity world, jumping to a position of (0,0,0). I tried removing the parent object and placing it in the world, but the same thing happens, even when all scripts are disabled, the gun still seems to jump to the origin.

I was wondering if any of you have had similar problems, and if so, is there any easy way to fix it?

Thanks,
-Andrew

Oh, I’m sorry, allow me to clarify…

when the gun is parented to the camera, it jumps to the camera’s position, the local origin, and when it is not parented, it jumps to the world origin.

The gun itself consists of two meshes, one for the body of the rifle, and one for the magazine, which is parented to the body. Only the body of the rifle is key framed in Maya, and the animation plays correctly, just in the wrong place…

Alright, I think I understand your problem. What’s happening(if my experience proves correct), is that your gun animation is setting the position of the gun to (0,0,0). So when it’s a child of the camera, the object moves to local position 0,0,0. When it’s not a child of anything, it just goes to world position 0,0,0.

To fix it:

  1. Create an empty gameobject.
  2. Put your gun into this object(so it’s a child of the gameobject).
  3. In the Unity Inspector, set the gun position to (0,0,0).
  4. Put the gameobject you’ve created into the Camera object(so it’s a child of the camera).
  5. Now, instead of dragging the gun around to position it, drag around the object you’ve just created.

Hope that helps,

Lincoln Green

While this does do what I want, I still want to get to the bottom of this… I’ll use your suggestion in the meantime…

Thank you,
-Andrew

Yes it does, actually. It means that your animation sets the position of the model to (0,0,0). To remove this effect, go into your 3D modeler and delete the keyframes for position.

This is extremely old, but I’m having the same problem while following a tutorial. The guy in the video tutorial is not having the same problem, though, and it appears that all of my settings are the same as his from what I can tell. Am I missing something?