How do I make a viewport gun that can play the same animation as the normal tool while being able to aim it?

I was making a gun system using securecast, but I ran into an issue. I’m using a viewport gun - I clone the tool with the primary part set to an aimpart, then PivotTo it to the camera at each new frame. Separately, I have a character that only has a transparent torso and hands that I also move to the camera to act as viewport hands. I was able to play the gun reload animations on the arms and aim and then unaim the gun by tweening a vector3 value that acts as an offset.
However I ran into a problem - I don’t know how to play the same animation on the viewport gun that I play on the actual gun.
I know that ACS just has two separate animations for the server and viewport, however I don’t want to animate the same thing twice.

Has anyone else who has made their gun system with aiming ran into this sort of issue? How did you solve it? Thank you.

1 Like

To play animation in a viewport frame, place everything under a wroldmodel inside the viewport frame

2 Likes

not what i meant, im not using viewport frames, the gun tool clone exists but only clientside and is pinned to the camera, which is why i called it a viewport gun

1 Like

that… is literally what everyone does

May I ask why would we tween parts instead of using the default roblox animation (that would replicate to the server)?

1 Like

Because to aim the gun I need to have it positioned exactly at the camera (gun’s primary part is an aimpart, so when it is at the camera’s position aiming happens), and to unaim it i use an offset vector3value

After weeks of trying to find the solution for this, I came up with this method:

  1. Clone a character from replicated storage that only has a humanoid with an animator, a torso and left and right arms and the corresponding motor6ds to link them. Later referred to as viewport arms.
  2. Clone the gun tool, parent it to the viewport arms.
  3. Set the viewport arms PrimaryPart to the gun’s aim part
  4. Disable the RightGrip weld under the right arm of the viewport arms and replace it with a motor6d
  5. At every render step, move the arms to the camera position + a vector3value offset
  6. When aiming, tween the offset to zero. Since the primary part of the arms is set to the gun’s aimpart, when the offset is zero the gun is in the aiming position.
  7. When unaiming, set the offset to the value you prefer, for me it is something along the lines of (0.5,-0.5,0.7)
  8. Play the same animations that you play on the player’s character on the viewport arms.
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.