Viewmodel camera doesnt seem to stay in one place

Hi, im making a viewmodel with an animated camera. But, the camera seems to move down (or up it might depend) and not stay in one place. How would I fix that? I’ve searched in the devforum but not even one helped on my problem.

local offsetCFrame = viewmodel.Torso.CFrame:ToObjectSpace(viewmodel.Camera.CFrame) local viewmodelPos = camera.CFrame * attributes.offset viewmodel:PivotTo(viewmodelPos) camera.CFrame *= offsetCFrame

2 Likes

This is what worked for me which does movement and the camera returns back to original.

Keep in mind you only have to edit the offset local variable.


i cant tell if i did this wrong
local oldOffset = CFrame.new() -- Don't edit this! local offset = viewmodel.Torso.CFrame:ToObjectSpace(viewmodel.Camera.CFrame) local viewmodelPos = camera.CFrame * attributes.offset viewmodel:PivotTo(viewmodelPos) -- (Optional): Accumulate the time in seconds t += dt -- Cancel out the offset we applied in the previous frame camera.CFrame *= oldOffset:Inverse() -- Apply the new offset camera.CFrame *= offset -- Store the offset we have applied so we cancel it in the next frame oldOffset = offset -- Update the offset that will applied! offset = CFrame.Angles(math.sin(t), 0, 0) --You can change this however you want! -- Proof (Optional): You can update the original cframe without affecting the offset camera.CFrame *= CFrame.new(math.sin(t)*10, 0, 0) --You can change this however you want!

1 Like

Me neither unfortunately I cannot read your mind to know how you setup your offset in attribtes.offset

Also you can format code using ```

And you can remove the math.sin stuff from the original, that was just for demonstration on how to update the offset variable. These 2 lines.

2 Likes

the offset is just a cframe value that just moves the viewmodel