- Home /
Having issues with position in my animation
I am in the middle of making an fps shooter game for vr and wanted to animate the guns to switch between 3 different modes (pistol, shotgun, and sniper). To do this I used the same meshes for all 3 models and put them under an empty parent object. Then I made an animation for each one and saved the position and scale for all the pieces. Animating from the pistol to the shotgun works as expected, but when I try to go from the shotgun to the sniper I run into an issue. I have 2 objects that make up the scope and when animated they go to right position in terms of what it says on the transform, but it isn't the correct area on the gun. I double checked and when I just put a prefab of the sniper itself the scope has the same position but for some reason it's not correct on the animated gun. Here's a screenshot of the sniper and the transform on the scope pieces (plane.004 and plane.006) along with the position of the 2 objects in the Sniper animation on the bottom.
Here's a screenshot with the position on the actual animated gun along with the animator to show that it is in the Sniper state. On the left of the scene view you can see the scope is floating a good amount in front of it and not where it originally was.
Thanks so much for any help and if I can clarify anything I didn't explain well please ask!
Answer by N-8-D-e-v · Jun 20, 2020 at 09:11 PM
Just parent the one piece of the scope to the other, then they will stay together, if this doesn't work, try deleting the animation and remaking it, you may have added some extra keyframes without knowing it
I tried remaking it a few times but to no avail. I also tried parenting 1 piece to the other and it also didn't work. Both pieces move to the same incorrect place, not just 1.
How are you dealing with weapon switches? Are you using SetActive, or something else like changing the mesh of a mesh renderer
All the guns are made up of the same pieces, so the animation is just moving and scaling the pieces to their place for each gun. And I'm using triggers from any state to activate them.
Your answer
![](https://koobas.hobune.stream/wayback/20220613001343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation Clobbers Position 2 Answers
Play animation as the value changes from 0 to 1 with changing GameObject's position in unity 0 Answers
In animations, is it possible to only add transform values instead of setting it? 2 Answers
Getting imported animated object position 0 Answers
My child move with the parent but can't move on it when the parent is moving 3 Answers