Trying to achieve a sine wave but don't know how to execute it

i usually dont script i usually build but i wanted to create something cool
I am trying to acheave a good sine wave for my breathing animation but i cant get sines to work and im using my own method for breathing wich is more of a triangle wave

local SineW = 0
local function Bsine ()

		if Breath == true then
			
		SineW = SineW + -0.0001   
	if SineW <=-0.025 then --lowest hight
	Breath = false
	end
		
					
				end


if Breath == false then
		
		
						
		SineW = SineW + 0.0001
		 
		if SineW >=-0.005 then -- highest hight
		Breath = true			
	end

end

all the solutions i found on Dev-fourm and Dev-hub i havent really helped with it so i just made my own solution that i prefer not to use. it goes into a offset with Cframe data and i just add it in.

how would i execute a sine wave that i correct. {{This script is run in RenderStepped!}}

You can get sine values from math.sin.

local value = math.sin(x)

and x is the argument to the sine function.
You can loop x from 0 to 2pi and then start again from 0.

local INCREMENT = 0.05
local angle = 0

while true do
	print(math.sin(angle))
	angle = angle + INCREMENT
	wait()
	if angle >= (math.pi * 2) then
		angle = 0
	end
	print(angle)
end

As x increases, y (angle) oscillates* between 1 and -1. You can use the value of math.sin(angle) in your script.
And as @Kacper pointed out, you’ll want to set angle to 0 when it reaches 2 * PI

8 Likes

I suggest changing angle back to 0 when it reaches 2*pi, so the angle variable doesn’t go out of range. Also it doesn’t fluctuate, it oscilates.

1 Like

I’ll try that I took a break from scripting today
I think that would be the solution but I’ll try it

So temporarly I’m setting that as solution

Thanks for explaining that because I didn’t understand the hub about it

1 Like

Note : actual math
Isn’t y=sin(0.05 x pie x Y) the same frequency as what you sent because if so I’ll use this on a graphing calculator to visually check what it is.

Also y=sin(F)
F=0-6.3