I have made a viewmodel and wanted it to sway using Hook’s Law and following @EgoMoose VIdeo on the topic.
I ended with the following scipt that doesnt work at all. Instead it rotates the viewmodel as i rotate the camera.
RunService.RenderStepped:Connect(function(deltaTime)
local Current, Velocity, Target = WeaponViewmodel.PrimaryPart.CFrame.LookVector, Vector3.new(), camera.CFrame.LookVector
local AngleMaxDistance = 0.15
deltaTime *= 60
local k, friction = 0.005 * deltaTime, 0.175
local PrimaryPartCFrame = WeaponViewmodel.PrimaryPart.CFrame
local Distance = (Target - Current)
local Force = Distance * k
Velocity = (Velocity * (1 - friction)) + Force
local pos = Current + Velocity
SwayCFrame = CFrame.new(pos)
WeaponViewmodel:SetPrimaryPartCFrame(camera.CFrame * MainCFrame * AimingCFrame * BobbleCFrame * SwayCFrame)
end)
If anyone could help me figuring out what I am doing wrong please, thanks !