My gun's aiming does not work right

Hey! I’m working on a fps system which uses the actual characters arms as a viewmodel.

To do this, I modify the arms motors to act like a viewmodel:

local NewCameraCFrame = CameraCFrame * AimOffset

local LeftShoulderC0 = TorsoCFrame:Inverse() * (NewCameraCFrame * CFrame.Angles(0,math.rad(-90),0) * CFrame.new(0,-1,1))
local RightShoulderC0 = TorsoCFrame:Inverse() * (NewCameraCFrame * CFrame.Angles(0,math.rad(90),0) * CFrame.new(0,-1,1))

This works fine, but for some reason my aim offset doesn’t work?

To get the aim offset, I use this:

local AimOffset = GunAimPartCFrame:Inverse() * CameraCFrame

When not aiming it’s as it should be:

But then when I aim it just slightly moves the arms:

My tool is set up like this:

How can I fix this? I’m pretty sure my tool is set up correctly, just how I’m calculating the aim offset is wrong. It should have the gun at the center of the screen and the camera looking down the sight.

4 Likes

What I found was instead of multiplying the aimpart cframe by the camera cframe multiplying it by the cframe of the root part of the view model works

4 Likes

I’m not using a viewmodel as said in the post, I’m setting the C0 of the moror6d under both arms to act as a viewmodel

2 Likes

ok multiply the cframe of the camera twice

2 Likes

It just makes the arms fly away, why would that work anyways?

2 Likes

idk just use a preset offset or something thats how ive always done it

2 Likes

That’s what I’m trying not to do

2 Likes

try moving the aimpart closer the to sight

2 Likes

The aim part is properly lined up where it should be as I said in the post, just something with how im getting the offset is wrong

2 Likes

Could you do camera.CFrame = aimPart.CFrame?

2 Likes

Since

Why does CameraCFrame need to be multiplied twice?

Shouldn’t AimOffset be set as:

local AimOffset = GunAimPartCFrame:Inverse()

I can already tell you that doesn’t work as it needs to be an offset, that’s just inversing the cframe which will return some random far away cframe

I recreated the problem and discovered that it flys away because it is getting the CFrame from the AimPart but the AimPart is welded to the Arms. So as the arms move, the Aim changes in relativity to the arms and makes them fly away.

As a Solution, I have tried to attach the aim partly to the player and disconnected it from the arms. To make this happen, you can either make it so that when the tool is equipped, the aim part’s weld changes to the player, ex: Torso, or make the part/attachment already attached to the player.

1 Like