What do you want to achieve? Bottom left camera model at all times
What is the issue? When I crouch (changes the humanoid hip height), held items don’t correctly teleport to the camera’s CFrame
What solutions have you tried so far? Tried teleporting to humanoidRootPart instead of camera, using PreRender, and using Position rather than orientation
function render.render()
local mouseDelta = UIS:GetMouseDelta()/50
local swayX = math.clamp(mouseDelta.X, -0.2,0.2)
local swayY = math.clamp(mouseDelta.Y, -0.2,0.2)
swayCF = swayCF:Lerp(CFrame.new(swayX, swayY, 0), .2)
for _, v in cam:GetDescendants() do
if v:IsA("Model") then
local camCFrame = cam.CFrame
v:SetPrimaryPartCFrame(camCFrame * swayCF)
end
end
end
Since this is a module and can’t run RunService I have them in a local script that calls the module.
Try applying an offset cframe (before applying the sway cframe) when you are crouching. Just make crouching an attribute perhaps so it’s easier to detect.
That solved the issue; however, I am presented with another problem. When looking up, down, etc., the tool gets further away from the camera view while crouching. Here is the updated version:
local swayCF = CFrame.new()
local crouchOffsetCF = CFrame.new()
function render.render()
local mouseDelta = UIS:GetMouseDelta()/50
local swayX = math.clamp(mouseDelta.X, -0.2, 0.2)
local swayY = math.clamp(mouseDelta.Y, -0.2, 0.2)
swayCF = swayCF:Lerp(CFrame.new(swayX, swayY, 0), 0.2)
local targetCrouchOffset = char.PlayerValues.inCrouch.Value and CFrame.new(0, -1, 0) or CFrame.new(0, 0, 0)
crouchOffsetCF = crouchOffsetCF:Lerp(targetCrouchOffset, 0.2)
local finalCameraCFrame = cam.CFrame * crouchOffsetCF * swayCF
for _, v in cam:GetDescendants() do
if v:IsA("Model") and v.PrimaryPart then
v:SetPrimaryPartCFrame(finalCameraCFrame)
end
end
end