# How can I make math.sin() slower?

hi, I am using sine waves to create a bobbing effect but this happens;

code;

``````function guns:Update(dt)
self.bobbing = Vector3.new(math.sin(tick()*100),math.sin(tick()*100),0)
self.Character.Torso["Right Shoulder"].C0 = Variables.RightC0 * CFrame.new(self.bobbing)
end
``````

when I call it;

``````self.Connect = game:GetService("RunService").RenderStepped:Connect(function(dt)
self:Update(dt)
end)
``````

How can I make it slower?

1 Like

Maybe try changing the â100â to something else.

hm, no I think itâs because the loop speed, is there any other way?

The value passed into the sine function is the only thing that should be affecting the speed of the oscillation, so no.

I wouldnât mess with the RunService loop, anyway. Just try using a number lower than 100 in the sine function and see if that works.

1 Like
Code format sent

local playing, completed = Enum.PlaybackState.Playing, Enum.PlaybackState.Completed
local style, dir = Enum.EasingStyle.Sine, Enum.EasingDirection.InOut

local sin = script:WaitForChild(âSineâ) --remember, the NumberValue; it will act as the âtimeâ for our curve
local isSprinting = char.Sprint:WaitForChild(âIsSprintingâ) --aah, finally it came in use

local dur, durSprint = 0.675, 0.5 --tween duration while walking & sprint time, respectively

âthe tweens for walking and sprinting (I made them reverse, but running only once)
local ti, tiSprint = TweenInfo.new(dur, style, dir, 0, true), TweenInfo.new(durSprint, style, dir, 0, true)
local oneTween, oneSprintTween = ts:Create(sin, ti, {Value = 1}), ts:Create(sin, tiSprint, {Value = 1})

âoffset = camera offset; maxRandomBounds = for clamping the Perlin Noise value for point0
local offset, maxRandomBounds = 0.25, 0.5

âpoint0 and point2 are on the right and left side, respectively
local point0, point2 = Vector3.new(offset, 0, 0), Vector3.new(-offset, 0, 0)

âremember, point1 is in the middle; weâll be using Perlin Noise for the X position
local point1 = Vector3.new(0, -offset, 0)

local ti2 = TweenInfo.new(dur / 2, style, dir)

âtween back to the origin
local tweenBack = ts:Create(hum, ti2, {CameraOffset = Vector3.new(0, 0, 0)})

âtween to point0 so it can bob back and forth
local begTween = ts:Create(hum, ti2, {CameraOffset = point0}) --no, Iâm not making the tween beg!

âthis will be for our Perlin Noise, the higher the inc, the more random
local counter, counterInc = 1, 0.1

âthis will be true once begTween starts playing (to make it not play again)
local running = false

This text will be hidden

When trying to show code on the devloper forum, please use code blocks. If you donât know how to do code blocks there is a tutorial here

Basically when replying just click the symbol up the top, (</>) and it should work.

You can just try lerping it like this

``````local alpha = 0.1
function guns:Update(dt)
self.bobbing = Vector3.new(math.sin(tick()*100),math.sin(tick()*100),0)
self.Character.Torso["Right Shoulder"].C0 =
self.Character.Torso["RightShoulder"].C0:Lerp(Variables.RightC0 * CFrame.new(self.bobbing), alpha)

end
``````

also for anyone wondering why not decrease â100â thatâs because 100 determines the amplitude of the wave not the speed at which the values change

also OP the larger the alpha value the more incremental the change would be, lerping doesnât necessarily make it slower but it just moves to the target value in specified increments determined by the alpha

1 Like