ROBLOX viewmodel script| How to make animated camerashake/bob work?

I have a ViewModel gun script and basically, instead of using a scripted camera shake, it’s an animated camera shake instead. This is possible by animating the part that the player views out of. Example: CameraPart.

Since the CameraPart is animated to rock side to side, adding a script that allows the player to view out of the CameraPart will typically allow the camerashake to take effect and the players screen will begin to shake.

Example using a CameraLock Plugin:

But the issue is when we actually script the viewmodel without the plugin, and make the player view out of the camera part. Nothing really shakes at all. Example.

One thing that may be causing the issue here that me and a scripter saw today was that the CameraPart that is animated to move, isn’t moving at all. It’s frozen. Any tips and examples to fix this at all? Thanks!

2 Likes

Whoa, I believe we will need more information, is the camera part rigged via Motor6D?

Is the camera type set to scriptable? How are you making it?

Perhaps?

Camera.CFfame= part.CFrame

First off, Yes. The CameraPart is rigged via Motor6D. It’s a CameraPart with a Motor6D, child to the HumanoidRootPart, and the CameraPart has a StringValue in it called “CamPart” I don’t know if the Stringvalue is neccesary for scripting, but I know that It was needed in order to run the temporary cameralocker plugin on it.

Here’s a note from the scripter who is working on it.

Oh wait shouldn’t that be the other way around?

Set the camera CFrame to the camera part.

Not set the camera part CFrame to the camera CFrame?

Typo?

Atm all the script does is sets the viewmodel’s primary part’s cframe (the camerapos part) to the cframe of the camera, if I set the camera cframe to the camera part there wouldn’t be anything to move the part itself

Oh I’m starting to see, but can I also see the camera part rig part0 and part1 Motor6D Joint? And also the rig structure as viewed in bone form using a plugin like rig edit lite, also to double confirm the camera that is shaking due to the animations is the camera part right?

Yes, the camera is shaking due to animating the camera.

Here’s the bone structure. The CameraPart is location at the circled top.

Thanks a lot, also is the camera type scriptable? the default camera scripts may also interfere with the rolling of the camera shake.

Ok so judging by the description of the script

It’s like this:

	RunService.RenderStepped:Connect(function()
		if camera.CameraType ~= Enum.CameraType.Scriptable then
			camera.CameraType = Enum.CameraType.Scriptable
		end
end)--ensure it's set to scriptable

--to move view model to the camera
cameraPart.CFrame = camera.CFrame

And for some reason it’s not shaking. Assuming the CameraPart Motor6D is being animated and has the .Transform property being edited by the animations.

--weld formula
part1.CFrame * C1 == Part0.CFrame * C0
--replace it with the variables
Part0.CFrame * C0 = part1.CFrame * C1 
HumanoidRootPart.CFrame * C0 = CameraPart.CFrame * C1 
--assume transform is being applied to humanoid root part, not too sure about this
HumanoidRootPart.CFrame * C0*transform = CameraPart.CFrame * C1 
--solve for cameraPartCFrame
--inverse both sides by C1
CameraPart.CFrame = HumanoidRootPart.CFrame * C0*transform*C1:Inverse()

--Or is it the other way around? solving for HRP, IDK

Try this formula out, I believe either the camera scriptable is causing the issue, or somehow the Motor6D Transform CFrame animation is not being applied somehow.

Manually including the transform property into the equation may work…never saw this problem before, I can only recommend trying things out.

cameraPart.CFrame = camera.CFrame*Motor6D.Transform
--maybe even
cameraPart.CFrame = camera.CFrame*Motor6D.Transform:Inverse()

Edit: If possible can I also see a video of the camera part being animated, within the animation editor and in game? Maybe positioning the viewmodel into a dummy R15 character so you can view from a third person perspective might also help debug the problem.

cameraPart.CFrame = dummyHead.CFrame
1 Like

We are going to give that a try too, thanks! See you in a bit.

Can you link the plugin, I’m in need of this animated camera shakes