The farther away my camera is from the character, the more the gui sways. The exact opposite happens when im in first person mode.
I want to make it so the gui sway is constant regardless of how far away the camera is.
edit: tbh i think the issue lies in the velocity of the camera rather than the distance
Video:
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = game:GetService("Players").LocalPlayer
local Spring = require(ReplicatedStorage.ModuleScripts.Spring)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local MainFrame = script.Parent
local originalPosition = MainFrame.Position
local originalRotation = MainFrame.Rotation
local swaySpring = Spring.new(Vector2.new(0, 0))
swaySpring.Speed = 7.5
swaySpring.Damping = 0.4
local rotationSpring = Spring.new(0)
rotationSpring.Speed = 10
rotationSpring.Damping = 0.6
local lastCamPos = Camera.CFrame.Position
RunService.RenderStepped:Connect(function(delta)
local camPosition = Camera.CFrame.Position
local camDelta = (camPosition - lastCamPos) / delta
lastCamPos = camPosition
local swayInput = Vector2.new(camDelta.X, camDelta.Y) * 0.4
local rightVector = Camera.CFrame.RightVector
local moveDir = Humanoid.MoveDirection
local sideways = moveDir:Dot(rightVector)
local tiltInput = sideways * 1
swaySpring.Target = swayInput
rotationSpring.Target = tiltInput
local offset = swaySpring.Position
MainFrame.Position = originalPosition + UDim2.new(0, offset.X, 0, offset.Y)
MainFrame.Rotation = originalRotation + rotationSpring.Position
end)
RunService.RenderStepped:Connect(function(delta)
local camPos = Camera.CFrame.Position
local camToCharDistance = (Character.PrimaryPart.Position - camPos).Magnitude
local camDelta = (camPos - lastCamPos) / (delta+(camToCharDistance/10))
lastCamPos = camPos
local adjustedCamDelta = camDelta
local swayInput = Vector2.new(adjustedCamDelta.X, adjustedCamDelta.Y) * 0.4
local rightVector = Camera.CFrame.RightVector
local moveDir = Humanoid.MoveDirection
local sideways = moveDir:Dot(rightVector)
local tiltInput = sideways * 1
swaySpring.Target = swayInput
rotationSpring.Target = tiltInput
local offset = swaySpring.Position
MainFrame.Position = originalPosition + UDim2.new(0, offset.X, 0, offset.Y)
MainFrame.Rotation = originalRotation + rotationSpring.Position
end)
on relative line four of the code I just provided, change the number ten if the results aren’t good keep messing with it. If the results are just toally bad tho then it’s proably not soluton.
sorry for the late reply but i found a better solution for my problem
local lastCamCFrame = Camera.CFrame
RunService.RenderStepped:Connect(function(dt)
local camCFrame = Camera.CFrame
local camDelta = lastCamCFrame:ToObjectSpace(camCFrame)
lastCamCFrame = camCFrame
local x, y, z = camDelta:ToEulerAnglesXYZ()
-- This is what i added^
local swayInput = Vector2.new(-math.deg(y*0.7), -math.deg(x)) * 3
local rightVector = camCFrame.RightVector
local moveDir = Humanoid.MoveDirection
local sideways = moveDir:Dot(rightVector)
local tiltInput = sideways * 1
swaySpring.Target = swayInput
rotationSpring.Target = tiltInput
local offset = swaySpring.Position
MainFrame.Position = originalPosition + UDim2.new(0, offset.X, 0, offset.Y)
MainFrame.Rotation = originalRotation + rotationSpring.Position
end)