So I found myself editing FE Gun Kit Viewmodel and I ran into an issue where when I aim, the viewmodel doesn’t go where it is supposed to: Not Inversed.wmv (1.2 MB)
As you can see, the viewmodel is not going to the attachment (green circle)
So I tried inversing the CFrame: Inversed.wmv (1.6 MB)
But it didn’t fix the issue.
Code:
aimOffset:
-- this is a module
return
CFrame.new(
script.Parent.Handle.AimPoint.CFrame.X,
script.Parent.Handle.AimPoint.CFrame.Y,
script.Parent.Handle.AimPoint.CFrame.Z
):Inverse() -- In this example it is inversed
AimScript:
local aimOffset = require(Camera.Arms:FindFirstChild("aimOffset"))
local aimcf = interpolator(aimOffset)
cf = cf * aimcf(aim)
-- aim is a spring created for aiming
-- cf is the viewmodel's CFrame
, but I tried it without the :inverse() and it didn’t fix the issue
– this is a local script
local offset = require(script.Parent.aimOffset)
local viewModel = script.Parent.Model
local gun = script.Parent.Parent.Parent
local handle = script.Parent.Handle
local aim = handle:WaitForChild(“AimPoint”)
gun.Equipped:Connect(function()
local handleCF = handle.CFrame
local aimCF = aim.CFrame
while true do
viewModel.PrimaryPart = handle
viewModel.SecondaryPart = aim
viewModel.CFrame = handleCF:ToWorldSpace(aimCF) + offset
wait(0.1)
end
end)
So this is my code. I am new to roblox so I am not familiar with the ways to fix this issue.
The lua code was taken from this video: - YouTube
The problem is that the CFrame.new constructor takes the absolute position of the point, but you’re passing in local positions.
So instead of using CFrame.new, use the CFrame.fromEulerAnglesXYZ constructor, or use CFrame.fromMatrix.
You can also use CFrame.new but use CFrame.new with the absolute position of the point, which you can get with Handle.AimPoint.Position.