ohhhh but notsad… you absolute stupid silly buffon, you just answered your own question!
i know i need to use cframes, but i don’t know how to get the position i need to use for each gun
should i have an invisible part called “aimpart” and lerp that, but even then, where should i lerp it so it’s on the center of the screen while not covering everything up
how do i make the viewmodel arms “rotate” towards the gun but stay on their current cframe? (if that makes sense)
this is a real hassle for a cframe loser like me to do,
i did ask @awry_y (please see this i need you rn ) for help at one point
the help i got was… very vague, but not really
i needed toooo calculate an offset?
i think it was something to do with aimPart.CFrame - targetPart.CFrame
so sure, maybe i can just lerp the gun to the result of that subtraction
but what about the viewmodel arms? how do i uh
Best way to do it is to check when the player holds down their right mouse button and then just adjust the ViewModel CFrame. For the ViewModel make two arms and then have them joined to a root part, you can also use PivotTo to achieve this and some Lerping. For my guns I have a attachment called aim, I just get its world CFrame and then move the ViewModel CFrame in relative to that.
I use this code here to get the ADS effect, I would also use lerping so that it looks smoother.
This returns the offset. Then you can copy that offset and apply it to the viewmodel like so:
local ViewModel = -- your viewmodel.
local aimOffset = CFrame.new(X,Y,Z)
RunService.RenderStepped:Connect(function()
ViewModel:PivotTo(Camera.CFrame*aimOffset)
end)
damn i just got up and did that offset thing you wanted me to do
i don’t think this is quite the result we were expecting
not sure what i did wrong? i multiplied by the offset and all that
local function AimGun(weapon: Tool, viewmodel: Model)
local viewmodelHandle: BasePart = viewmodel:FindFirstChild("Handle")
local viewmodelAimPart: BasePart = viewmodelHandle:FindFirstChild("AimPart")
-- get initial viewmodel pivot
local initialPivot = viewmodel:GetPivot()
-- calculate the offset
local offset = camera.CFrame:ToObjectSpace(CFrame.new(viewmodelAimPart.Position)).Position
print(offset)
-- pivot the viewmodel (change to lerping later)
rService:BindToRenderStep("AimGun", Enum.RenderPriority.Camera.Value, function()
viewmodel:PivotTo(camera.CFrame * CFrame.new(offset))
end)
-- setup a connection to stop the ADS
local adsReleasedConn: RBXScriptConnection
adsReleasedConn = mouse.Button2Up:Connect(function()
-- unbind from renderstep, reset viewmodel position and disconnect
rService:UnbindFromRenderStep("AimGun")
viewmodel:PivotTo(initialPivot)
adsReleasedConn:Disconnect()
end)
end
local adsReleasedConn: RBXScriptConnection
adsReleasedConn = mouse.Button2Up:Connect(function()
-- unbind from renderstep, reset viewmodel position and disconnect
rService:UnbindFromRenderStep("AimGun")
viewmodel:PivotTo(initialPivot)
adsReleasedConn:Disconnect()
end)
Inefficient method. Use:
mouse.Button2Up:Once(function()
-- unbind from renderstep, reset viewmodel position and disconnect
rService:UnbindFromRenderStep("AimGun")
viewmodel:PivotTo(initialPivot)
end)