Motor6D Transform shakes wierdly in FPS mode (incl. footage)

I want to place the arms of my character below my camera in FPS mode. This is the code that runs when in FPS mode.

RunService.Stepped:connect(function(_, dtt)
	local goal = cam.CFrame * CFrame.new(0, -2, -1)
	local from = rarm.Part0.CFrame * C0
			
	rarm.Transform = from:ToObjectSpace(goal) * C0
end)

This is the result

As you can see, it’s perfectly smooth when panning sideways
But tilting up and down induce some kind of shaky behavior.

Where does this shaking come from and how do I fix it?
I’ve noticed the camera cframe is not same in stepped as in renderstepped, could that be an issue?

2 Likes

Or should I abandon the use of Transform completely because it doesn’t update the part positions in renderstepped?

I’m not at all experienced with FPS scripting, but bear with me.


I’m guessing the issue lies in the transform, since that treats it like a separate from the camera.
However, using RenderStepped to determine the camera CFrame by using a viewModel could work;

local function onUpdate(dt)
	viewModel.Head.CFrame = camera.CFrame;
end

game:GetService("RunService").RenderStepped:Connect(onUpdate);

And creating a script utilising the viewModel to attach the weapon to;

local repWeapon = --path to the weapon
local weapon = repWeapon:Clone()

weapon.Parent = viewModel --viewModel being what you use to determine the head position
viewModel.Parent = camera

local joint = Instance.new("Motor6D")
joint.C0 = CFrame.new(0, -2, -1); --using your original values
joint.Part0 = viewModel.Head
joint.Part1 = weapon.Handle --change 'Handle' with a part in the weapon model if necessary
joint.Parent = viewModel.Head

Again, I’m not at all experienced with FPS camera/models, but it was fun trying to learn more about it and I hope it helped you enough. If not, this is where the code came from and which was most clear to me.

If anything is unclear, I’m sure you’ll find it in the topic or the replies.

Sure I could always create a fake gun model and move it along with the camera.
But simply setting the arm transformation would’ve been much easier :confused:

Guessing I’ll have to cframe it all anyways.

Would it?


But, I found this topic that uses a RenderStepped tranform, yet only for the ADS animation and not for the gun placement. They apply the use of CFrames for that.

1 Like

I think the issue you’re seeing here may be related to the fact that you’re using Stepped instead of RenderStep and hooking the step immediately before the camera step i.e

RunService:BindToRenderStep('MyBindingName', Enum.RenderPriority.Camera.Value - 1, function(dtt) 
	local goal = cam.CFrame * CFrame.new(0, -2, -1)
	local from = rarm.Part0.CFrame * C0
			
	rarm.Transform = from:ToObjectSpace(goal) * C0
end)

To expound on this, rendering happens first in the game loop, then physics (stepped), so what you’re probably seeing is the time between gun updates because it isn’t moved before the camera render step.

The reason side to side looks fine is because Roblox is taking care of that for you by rotating the character, which in turn rotates the gun.

The issue is that Transform does not apply its transformation in renderstepped, its applied after Stepped, at which point the frame is already rendered.

@Iemny Honestly I like your suggestion!
Why not render the entire weapon in a separate viewport? Would get rid of having your gun go through the walls. It’s how all the real FPS games do it.

Good suggestion! I might just do that :slight_smile:

1 Like


It works!

It does have some white artifacts on the outline of the gun though… but maybe this is a viable solution anyways.

1 Like

I think for the white outline you can kind of improve that by making the BackgroundColor3 on the ViewportFrame like a grayish color.

1 Like

Glad to have helped! We both got a little smarter today.

1 Like

Oh I’d never think of that!
Looks much better now, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.