Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

CFrame issues with my fps, aim CFrame affecting main CFrame?

Asked by 4 years ago

I was messing around with the CFrames for my ViewModels and found that the aim CFrame effected the normal CFrame. For instance, if I included in my aim CFrame that Y Axis was 1.45, the main CFrame Y Axis would be moved as well.

Framework script (localscript):

--wait until game is loaded
repeat wait() until game:IsLoaded()

--local variables
local plr = game.Players.LocalPlayer
local char = plr.Character
local cam = workspace.CurrentCamera
local mouse = plr:GetMouse()

--service variables
local runs = game:GetService("RunService")
local tweens = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")

--misc variables
local modules = rs:WaitForChild("Modules")
local models = rs:WaitForChild("Models")
local running
local aiming

--CFrame variables

local maincf = CFrame.new()
local aimcf = CFrame.new()

--gun variables

local currentEquipt
local primary = "test"
local secondary
local currentData

--functions

plr.CameraMode = Enum.CameraMode.LockFirstPerson

function setup(gun)
    currentEquipt = models:WaitForChild(gun)
    currentEquipt.PrimaryPart = currentEquipt:WaitForChild("Handle")
    currentEquipt.Parent = cam

    currentData = require(modules:FindFirstChild(gun))

    maincf = currentData.maincf
    aimcf = currentData.aimcf

    for _,v in pairs(currentEquipt:GetChildren())do
        if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
            if v.Anchored and not v.CanCollide then
            else
                v.Anchored = true
                v.CanCollide = false
                print("Fixed "..v.name..".")
            end

            if v:FindFirstChild("Weld") then
                v.Weld:Destroy()
            end
        end
    end
end

runs.RenderStepped:Connect(function()
    if currentEquipt then
        currentEquipt:SetPrimaryPartCFrame(cam.CFrame
            *maincf
            *aimcf
        )
    end
end)

mouse.Button2Down:Connect(function()
    aiming = true
end)

mouse.Button2Up:Connect(function()
    aiming = false
end)

setup(primary)

Module:

local test = {}
test.maincf = CFrame.new(0.67,-.45,-2.55)
test.aimcf = CFrame.new(0,-.56,0)
return test

Please try and help, I'll be answering questions if you have any.

Answer this question