Game Gun Animation Question...

In my game, any human character needs to be able to hold a gun. Each human character can hold different guns. There will be multiple guns, each with different sprite representations (simple ones but different sizes and colors, etc).

I would like to superimpose the images of the guns on top of the images of the characters in order to avoid excessive sprite work and in order to make it more adaptable. However, as characters animate, their arms usually move around from frame to frame. The gun would presumably need to move with the arms.

I’m guessing the best way to do this would be to find a way to configure the location of the gun per frame. I could probably dream up a reasonably complex solution with each image being mapped through a manager class to entries in config files, but what is the usual way to do this sort of thing in Unity? Perhaps associating scripts with images or animations might be a good idea? I know that animations can call upon scripts at specific frames through events, but every single frame must be configured.

Since you already have the animations for your characters, I would go about it this way…

Add an empty game object as a child to each player character, since it will be “following” the hand of the characters you might name it Hand. Select your characters one by one and go into the animation window. Go into each animation and do an Add Property, since you added the child object Hand, this should now be available in the popup. Add a Transform/Position curve for the Hand. Go through your animation’s keyframes and make sure that the Hand is positioned correctly at each keyframe (the easiest way to get this right is probably to place a weapon as a child to the Hand object, make sure that the weapon is placed at 0,0). This way you’ll get an empty object that follows each character’s hand throughout their animation cycles and once you need to add a weapon, just add it as a child to the Hand object. For characters that are very similar, you will be able to copy the animation curves between the animations, cutting down on the work needed.

It will take some work, but I think that this is the easiest, most flexible way of doing it.

1 Like

Actually, no, I have not done most of the animations for characters and still may redo the ones I have done later. Thus if there is a better way that involves redesigning animations, it would not be bad to consider.

I can give what you suggested a try, though.

This worked pretty well. I didn’t have to add a curve for the hand; it apparently worked with tangents.

I’m guessing I might consider redoing my sprites to use a hierarchical system, though it would also depend on how well this works with 8-bit NES style sprites.