Hello! I’m in the middle of making a weapon framework and have been testing everything just fine so far; Only when i used my FPS unlocker i’ve noticed really bad results. Everything is/was acting as if it’s being done twice, and ADS being massively broken.
Note: I’ve implemented an FPS counter to help with diagnostics. It’s on the top of the screen.
--i threw it in here in case someone wants to check if it's correct
spawn(function()
fps = 0
spawn(function()
while game:GetService("RunService").RenderStepped:Wait() do
fps = fps + 1
end
end)
while wait(1) do
game.Players.LocalPlayer.PlayerGui.Game.FPS.Text = "FPS : "..fps
fps = 0
end
end)
I checked up on framerate independent motion and added * deltaTime * 60
to any instances of the springs being shoved inside RenderStepped. This “seems” to have fixed most of bobbing issues but i’m still left with ADS not working. Example:
Locked:
https://gyazo.com/03565bc2c790f6923796932d388ed7da
Unlocked:
https://gyazo.com/e57fe72170e38332a59b6e13723e8a6c
Second try was limiting deltaTime to 1/60;
deltaTime = math.max(1/60,deltaTime)
Unlocked:
https://gyazo.com/f2ab99c00cbb76e59f75977857d3a6e7
Locked:
https://gyazo.com/aecebc8955f7fcdb58c017d79753dec1
I don’t have any other solutions to try since i’m pretty clueless about this.
Bobbing is calculated every frame, like this: (but mutliple times with multiple springs for other movements like sway)
local speed = 2
local modifier = 4
local workBobble = Vector3.new(math.sin(tick()*5*speed)*modifier, math.sin(tick()*10*speed)*modifier, 0)-- Vector3.new(Bobble_X,Bobble_Y,0)
self.springs.bobble:shove(workBobble * deltaTime * scalar)
Aiming itself is a bit more complex than that. Every frame 2 offsets (holding and aiming) are lerped between each other based on a spring’s X output. This output is pushed when clicking RMB and adjusted in the renderstepped function itself. both the adjustment and initial push have custom values.
Custom values:
--values
local ADS_AIMDOWNDIVIDER = 30 --30
local ADS_AIMDOWNSPEED = 0.6--0.6
RenderStepped function:
--lerping adjustment
self.lastAimLerp = self.aimLerp
self.aimLerp = self.aimLerp + self.springs.aim:update(deltaTime).X
if math.clamp(self.aimLerp,1,1) ~= self.aimLerp and self.aiming then
self.springs.aim:shove(Vector3.new(((1 - self.aimLerp) / ADS_AIMDOWNDIVIDER),0,0) * deltaTime * scalar)
end
if not self.aiming then
self.aimLerp = self.aimLerp / 1.1
end
--offset calculation
local offset = self.gun.Properties.HoldOffset.Value:lerp(self.gun.Properties.AimOffset.Value,self.aimLerp)
self.gun.Handle.CFrame = self.viewmodel.camera.CFrame:ToWorldSpace(offset)
Aiming function:
function fpsHandler:aim(toAim)
self.aiming = toAim
local tweeningInformation = TweenInfo.new(0.6, Enum.EasingStyle.Cubic,Enum.EasingDirection.Out)
if toAim then
local properties = { FieldOfView = self.properties.aimFOV or self.baseFOV }
local tween = tweenService:Create(camera,tweeningInformation,properties)
tween:Play()
self.springs.aim:shove(Vector3.new(ADS_AIMDOWNSPEED,0,0))
else
local properties = { FieldOfView = self.baseFOV }
local tween = tweenService:Create(camera,tweeningInformation,properties)
tween:Play()
self.springs.aim:shove(Vector3.new(-ADS_AIMDOWNSPEED,0,0))
end
end
end