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?
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.
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.
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.