guardusia
(guardusia)
March 26, 2025, 2:56pm
1
I do not know how to explain this issue, but I have a video of It.
Here’s the video:
And here’s my code:
local aimCF = CFrame.new()
local aimOffset = Vector2.new()
local camera = workspace.CurrentCamera
local LastCameraCFrame = camera.CFrame
local uis = game:GetService("UserInputService")
local viewmodel
local equipped = false
script.Parent.Equipped:Connect(function()
viewmodel = game.ReplicatedStorage.Viewmodel:Clone()
viewmodel.Parent = camera
equipped = true
end)
script.Parent.Unequipped:Connect(function()
viewmodel:Destroy()
equipped = false
end)
game:GetService("RunService").RenderStepped:Connect(function()
LastCameraCFrame = camera.CFrame
if equipped then
local mousedelta = uis:GetMouseDelta()
--if camera.CFrame == LastCameraCFrame then
aimOffset = aimOffset + Vector2.new(mousedelta.X, mousedelta.Y)
--end
local rot = camera.CFrame:ToObjectSpace(LastCameraCFrame)
local x,y,z = rot:ToOrientation()
local swayCF = CFrame.Angles(math.rad(math.clamp(-aimOffset.Y/8, -15, 15)),math.rad(math.clamp(-aimOffset.X/10, -15, 15)),0)
local offset = CFrame.new()
aimCF = aimCF:Lerp(swayCF, .2)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF)
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
if humanoid then
--local currentTime = tick()
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").MoveDirection.Magnitude > 0 then
local bobOffset = CFrame.new(0, -humanoid.CameraOffset.Y/3, -humanoid.CameraOffset.Z/3) * CFrame.Angles(0, math.sin(tick() * -4) * -.05, math.cos(tick() * -4) *-.05)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF * bobOffset)
--[[local bobbleX = math.abs(currentTime * 10) * .25
local bobbleY = math.abs(math.sin(currentTime * 5))
local bobble = Vector3.new(bobbleX, bobbleY, 0)
cf = cf:Lerp(CFrame.Angles(0, bobbleY, 0), .1)]]
end
end
end
end)
I just want do make a game like “Deadline” but I want to make It world war 1.
I appreciate your help.
refightx
(Jake)
March 26, 2025, 2:59pm
2
Is the sway the thing you are not liking?
Let me hop on my pc and I’ll give u a script
Ok. Here is how I have sway set up in my FPS Code.
local mouseDelta = uis:GetMouseDelta()/50
local swayX = math.clamp(mouseDelta.X, -0.25,0.25)
local swayY = math.clamp(mouseDelta.Y, -0.25,0.25)
swayCF = swayCF:Lerp(CFrame.new(-swayX, swayY, 0), .1)
That is how I have sway in my game.
guardusia
(guardusia)
March 26, 2025, 3:11pm
3
Now I have another problem
I think It get worse
refightx
(Jake)
March 26, 2025, 3:14pm
4
lol. Can you show me the code u have now?
guardusia
(guardusia)
March 26, 2025, 3:15pm
5
Here’s my code:
local aimCF = CFrame.new()
local aimOffset = Vector2.new()
local camera = workspace.CurrentCamera
local LastCameraCFrame = camera.CFrame
local uis = game:GetService("UserInputService")
local viewmodel
local equipped = false
script.Parent.Equipped:Connect(function()
viewmodel = game.ReplicatedStorage.Viewmodel:Clone()
viewmodel.Parent = camera
equipped = true
end)
script.Parent.Unequipped:Connect(function()
viewmodel:Destroy()
equipped = false
end)
game:GetService("RunService").RenderStepped:Connect(function()
LastCameraCFrame = camera.CFrame
if equipped then
local mousedelta = uis:GetMouseDelta()
local swayX = math.clamp(mousedelta.X, -15,15)
local swayY = math.clamp(mousedelta.Y, -15,15)
--if camera.CFrame == LastCameraCFrame then
aimOffset = aimOffset + Vector2.new(swayY,swayX)
--end
local rot = camera.CFrame:ToObjectSpace(LastCameraCFrame)
local x,y,z = rot:ToOrientation()
--local swayCF = CFrame.Angles(math.rad(math.clamp(-aimOffset.Y/8, -15, 15)),math.rad(math.clamp(-aimOffset.X/10, -15, 15)),0)
local swayCF = CFrame.Angles(math.rad(-aimOffset.X/8), math.rad(-aimOffset.Y/8), 0)
--local offset = CFrame.new()
aimCF = aimCF:Lerp(swayCF, .1)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF)
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
if humanoid then
--local currentTime = tick()
if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").MoveDirection.Magnitude > 0 then
local bobOffset = CFrame.new(0, -humanoid.CameraOffset.Y/3, -humanoid.CameraOffset.Z/3) * CFrame.Angles(0, math.sin(tick() * -4) * -.05, math.cos(tick() * -4) *-.05)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF * bobOffset)
--[[local bobbleX = math.abs(currentTime * 10) * .25
local bobbleY = math.abs(math.sin(currentTime * 5))
local bobble = Vector3.new(bobbleX, bobbleY, 0)
cf = cf:Lerp(CFrame.Angles(0, bobbleY, 0), .1)]]
end
end
end
end)
refightx
(Jake)
March 26, 2025, 3:18pm
6
I think this may be the problem
local mousedelta = uis:GetMouseDelta()
local swayX = math.clamp(mousedelta.X, -15,15)
local swayY = math.clamp(mousedelta.Y, -15,15)
--if camera.CFrame == LastCameraCFrame then
aimOffset = aimOffset + Vector2.new(swayY,swayX)
--end
local rot = camera.CFrame:ToObjectSpace(LastCameraCFrame)
local x,y,z = rot:ToOrientation()
--local swayCF = CFrame.Angles(math.rad(math.clamp(-aimOffset.Y/8, -15, 15)),math.rad(math.clamp(-aimOffset.X/10, -15, 15)),0)
local swayCF = CFrame.Angles(math.rad(-aimOffset.X/8), math.rad(-aimOffset.Y/8), 0)
--local offset = CFrame.new()
aimCF = aimCF:Lerp(swayCF, .1)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF)
Try this:
local mousedelta = uis:GetMouseDelta()
local swayX = math.clamp(mousedelta.X, -15,15)
local swayY = math.clamp(mousedelta.Y, -15,15)
--if camera.CFrame == LastCameraCFrame then
aimOffset = aimOffset + Vector2.new(swayY,swayX)
--end
local rot = camera.CFrame:ToObjectSpace(LastCameraCFrame)
local x,y,z = rot:ToOrientation()
--local swayCF = CFrame.Angles(math.rad(math.clamp(-aimOffset.Y/8, -15, 15)),math.rad(math.clamp(-aimOffset.X/10, -15, 15)),0)
swayCF = swayCF:Lerp(CFrame.new(-swayX, swayY, 0), .1)
--local offset = CFrame.new()
aimCF = aimCF:Lerp(swayCF, .1)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF)
refightx
(Jake)
March 26, 2025, 3:19pm
7
Wait I’m not really sure what your trying to fix is it the aiming sway or the sway in general?
guardusia
(guardusia)
March 26, 2025, 3:21pm
8
I want to fix aiming sway because I do not like how It works. It might be a math.clamp()
refightx
(Jake)
March 26, 2025, 3:22pm
9
oh ok, my bad. I thought u wanted sway to fix in general. So you want the aiming sway to be fixed. What is wrong with it?
guardusia
(guardusia)
March 26, 2025, 3:24pm
10
I filmed a video to explain my problem:
(Now I really need to go so I will answer later)
guardusia
(guardusia)
March 26, 2025, 3:42pm
11
Here’s example what I want:
guardusia
(guardusia)
March 26, 2025, 4:38pm
12
Do you have any other ideas? If not then it is very sad because I wanted to make this viewmodel 2 long years. Anyways thanks for help
refightx
(Jake)
March 26, 2025, 5:13pm
13
OHHH MY BAD I know why its bugging so hard in the second clip u sent
guardusia
(guardusia)
March 26, 2025, 5:15pm
14
don’t worry. What’s the problem for this issue?
refightx
(Jake)
March 26, 2025, 5:16pm
15
I accidentally put
local swayX = math.clamp(mousedelta.X, -15,15)
local swayY = math.clamp(mousedelta.Y, -15,15)
It should actually be
local swayX = math.clamp(mousedelta.X, -0.3, 0.3)
local swayY = math.clamp(mousedelta.Y, -0.3, 0.3)
I’m so sorry I actually just sold u so hard right there
note: change the 0.3 to any number just set it to what u like
refightx
(Jake)
March 26, 2025, 5:17pm
16
On the 0.3 I wasn’t very clear.
Keep it a decimal point, and also change the lerp amount on the SwayCF to come up with something u like.
refightx
(Jake)
March 26, 2025, 5:26pm
18
Ok, another idea. Try setting the CFrame of the view model before calculating sway, and then set the CFrame again after u have calculated the sway. When I was making my fps system setting the CFrame before calculating the sway worked for me.
Here is an example:
viewmodel:SetPrimaryPartCFrame(Camera.CFrame)
local sway = -- Calculate the sway however you want
viewmodel:SetPrimaryPartCFrame(Camera.CFrame * sway)
Try this, and let me know what happens.
guardusia
(guardusia)
March 26, 2025, 5:28pm
19
do something like
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF)
aimCF = aimCF:Lerp(swayCF, .1)
viewmodel:SetPrimaryPartCFrame(camera.CFrame * aimCF)
Like this?