Really weird raycasting behavior

Right now I’m countering this really weird raycasting glitch. I cast the ray base on player’s Torso, then the visual bullet will came out from a shoot part inside the tool, however this happens:

https://gyazo.com/af43650f30ff6103e9e57408677fa8bd

From the gif, you can see the bullet part is being offset to the ShootPart in the first few shots, but after I unequip it, everything works fine. This also happen if I happen wait for few seconds before I equip the weapon, it just feels like it has to initialize something.

I literally check everything else, including my Camera ViewModel, raycasting ignore list etc, and I kinda know the initial problem.
I replace the bullet part CFrame from this:

BulletPart.CFrame = CFrame.new(tool.ShootPart.CFrame.p,pos) * CFrame.new(0, 0, -dist / 2)

to this:

BulletPart.CFrame = CFrame.new(char.Torso.CFrame.p,pos) * CFrame.new(0, 0, -dist / 2)

Instead of placing it in the ShootPart, I change it to the Torso for testing purpose. And the result fixes the problem, however that shoots the BulletPart from Torso but not the ShootPart. which isn’t what I want.

Here’s the Raycasting Code: (dir is a function to cacaulate offset for accuracy)

local ray = Ray.new(char.Torso.CFrame.p, dir * WeaponConfigs.Range.Value)

Why does this difference in position of the gun and hands occur?


(This is an image of the video paused)

The animation hasn’t loaded yet, and the tool is connect to the Torso with Motor6d. But it still happen after the animation has been loaded. I tried to remove the animations, it still happens.
Moreover, the ShootPart seems to be falling down in a slow speed, from this gif, you can see the Yellow beam goes down and fall under the ground.
https://gyazo.com/462eb676b022d7f0bb246a9d609754c4

Maybe instead of having a physical part to shoot from you can store the offset position from the torso to shoot from?

I use a ViewModel and attach the weapon to the ViewModel Torso when the player is in First Person, and the ViewModel Root’s CFrame will be binded to the Camera CFrame in every RenderSteppeed
I’m still confused why is this happening, the parts of the tool is constantly dropping downwards until I go third person, which detach the gun from the ViewModel and attach it to the real character torso

This has been solved, the reason being because the ViewModel Root is not anchored. Despite I set it’s CFrame to the camera on every step, the Root is still falling into the void. But I have no idea why this fixed by itself after reequipping/ re-entering first person.