I want to find the aiming offset for a gun, so I put a aimPart marker at the spot where i want to aim down on. My problem is that I don't know the "formula" for getting the offset.
Code for aligning the gun to the camera:
RS:BindToRenderStep("Update",Enum.RenderPriority.Camera.Value + 1,function(dt)
local idleOffset = Offsets.Idle.Value
local aimOffset = idleOffset:Lerp(tool.Rifle.AimPart.CFrame:ToWorldSpace(workspace.CurrentCamera.CFrame),lerpValues.aim.Value)
local finalOffset = aimOffset
local mDelta = UIS:GetMouseDelta()
if Aiming.Value then
mDelta = mDelta * 0.1
humanoid.WalkSpeed = Settings.stats.AimWalkSpeed
else
humanoid.WalkSpeed = Settings.stats.EquipWalkSpeed
end
sway:shove(Vector3.new(mDelta.X/500,mDelta.Y/500))
local speed = 0.825
local modifier = 0.075
local swayPoint = Vector3.new(getSway(7.5,speed,modifier),getSway(10,speed,modifier),getSway(5,speed,modifier))
if Aiming.Value then
walkCycle:shove((swayPoint / 75) * dt * 15 * char.HumanoidRootPart.Velocity.Magnitude)
else
walkCycle:shove((swayPoint / 25) * dt * 60 * char.HumanoidRootPart.Velocity.Magnitude)
end
local springData = {
swayData = sway:update(dt);
walkCycleData = walkCycle:update(dt);
physicalRecoilData = physicalRecoil:update(dt);
cameraRecoilData = camRecoil:update(dt)
}
RootPart.CFrame = workspace.CurrentCamera.CFrame:ToWorldSpace(finalOffset)
RootPart.CFrame = RootPart.CFrame * CFrame.fromOrientation(springData.swayData.Y,springData.swayData.X,0)
RootPart.CFrame = RootPart.CFrame * CFrame.Angles(0,springData.walkCycleData.X,springData.walkCycleData.Y)
RootPart.CFrame = RootPart.CFrame * CFrame.fromOrientation(springData.physicalRecoilData.X,springData.physicalRecoilData.Y,0)
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.fromOrientation(springData.cameraRecoilData.X,springData.cameraRecoilData.Y,0)
end)
and the aimpart: https://gyazo.com/3a9df14fac81e074d20cf0a102a47ca3
When i try to use > workspace.CurrentCamera.CFrame:ToObjectSpace or > workspace.CurrentCamera.CFrame:ToWorldSpace and a bunch of other cframy stuff the gun just starts flying and spinning around when i aim
oh and also use the view source thing it makes the code easier to read
Thx for your time
