Motor6d Sine Wave

Hello. I am making a moving “head” light and im working on the motors for it. I somewhat got it to make a circle movement. This is what I want: https://gyazo.com/5b15ddd371d60c99314968fdd6f05f04
This is what I have:

Heres my script

for i,v in pairs(workspace.AWashes:GetChildren()) do
            spawn(function()
        if v.Name == "F1" then
            local t = 1
        while true do
                
            
    wait()
    
    t  = t + v.Tilt.MaxVelocity
    v.Tilt.DesiredAngle = math.sin(t*2.094)
    v.Pan.DesiredAngle = math.cos(t*2.094)
        end
        elseif v.Name == "F2" then
            local t = 1
        while true do
            
            wait()
                
            t  = t + v.Tilt.MaxVelocity
            v.Tilt.DesiredAngle = math.sin(t*2.094)
                v.Pan.DesiredAngle = math.cos(t*2.094)
                
            end
        elseif v.Name == "F3" then
                local t =1
            while true do

                wait()
                t  = t + v.Tilt.MaxVelocity
                v.Tilt.DesiredAngle = math.sin(t*2.094)
                v.Pan.DesiredAngle = math.cos(t*2.094)

            end
        elseif v.Name == "F4" then
                local t = 1
            while true do

                wait()
                t  = t + v.Tilt.MaxVelocity
                v.Tilt.DesiredAngle = math.sin(t*2.094)
                v.Pan.DesiredAngle = math.cos(t*2.094)

            end
    end 
            end)
end

4 Likes

Been one hour and no replies. Please help.

1 Like

Multiply the panning angles of the lights on the right by -1 (the ones with cos). Then for delaying the rotation of the outer lights, make a variable for horizontal translation of the waves and add it to the x-axis for a horizontal shift to the left (if you were to graph them as math functions), like so:

local c = 0 -- change this to how much you want to delay the outer lights
v.Tilt.DesiredAngle = math.sin((t + c)*2.094)
v.Pan.DesiredAngle = math.cos((t + c)*2.094)

Which can be simplified to:

local c = 0 -- change this to how much you want to delay the outer lights
t  = t + v.Tilt.MaxVelocity + c
v.Tilt.DesiredAngle = math.sin(t*2.094)
v.Pan.DesiredAngle = math.cos(t*2.094)
1 Like

I’m pretty sure i missed a step but it doesnt go in the same rotation but it still looks off.

Heres my script now

for i,v in pairs(workspace.AWashes:GetChildren()) do
	spawn(function()
		if v.Name == "F1" then
			local t = 1
			while true do


				wait()

				t  = t + v.Tilt.MaxVelocity
				local c = 1 -- change this to how much you want to delay the outer lights
				v.Tilt.DesiredAngle = math.sin((t + c)*2.094)
				v.Pan.DesiredAngle = math.cos((t + c)*2.094)
			end
		elseif v.Name == "F2" then
			local t = 1
			while true do

				wait()

				t  = t + v.Tilt.MaxVelocity
				local c = 2 -- change this to how much you want to delay the outer lights
				v.Tilt.DesiredAngle = math.sin((t + c)*2.094)
				v.Pan.DesiredAngle = math.cos((t + c)*2.094)

			end
		elseif v.Name == "F3" then
			local t =1
			while true do

				wait()
				t  = t + v.Tilt.MaxVelocity
				local c = 3 -- change this to how much you want to delay the outer lights
				v.Tilt.DesiredAngle = math.sin((t + c)*2.094)
				v.Pan.DesiredAngle = math.cos((t + c)*2.094)

			end
		elseif v.Name == "F4" then
			local t = 1
			while true do

				wait()
				t  = t + v.Tilt.MaxVelocity
				local c = 4 -- change this to how much you want to delay the outer lights
				v.Tilt.DesiredAngle = math.sin((t + c)*2.094)
				v.Pan.DesiredAngle = math.cos((t + c)*2.094)

			end
		end 
	end)
end

this is what it looks like now https://gyazo.com/d8d6741ca4446902720813dc52e75a27

Initially I thought you wanted half of the lights to spin clockwise and half to spin counter clockwise. Am I correct to assume that you want all four lights to rotate clockwise instead? If so, then our only problem is with the delay of each rotation. That is, the values we assign to c.

This should be an easy fix if we consider that c is an angle in radians that we use to offset the rotation of the lights. If you want to offset the rotation of a clock by a quarter of a full rotation, you set c = math.pi/2, or use c = math.rad(90) if you want to use degrees (since 90 degrees is 1/4 of a full rotation which is 360 degrees).

So say you want a light to be delayed by 23 degrees. You’d set c = math.rad(23).

This is the closest recreation I could get (by no means am I a builder):

Code I wrote:

local heartbeat = game:GetService("RunService").Heartbeat;

local lights = script.Parent:GetChildren();
local offset = 50;
local speed = 2.5;

for _,l in ipairs(lights) do
	if not l:IsA("Model") then continue; end
	
	local i = tonumber(l.Name);
	local baseHinge = l.BaseHinge;
	local hingeL = l.HingeL;
	local hingeR = l.HingeR;
	
	heartbeat:Connect(function()
		local t = os.clock() * speed + (math.abs(i) * offset);
		local baseAngle = math.sign(i) * math.deg(math.sin(t));
		local lightAngle = math.deg(math.cos(t) * 0.65);
		
		baseHinge.TargetAngle = baseAngle;
		hingeL.TargetAngle = lightAngle;
		hingeR.TargetAngle = lightAngle;
	end)
end

Model:
Sine Wave Lights.rbxm (8.7 KB)

Thats exactly what I need but. How do I do that for Motor6D?

I think I’m confusing you. I want half to be counter-clockwise with delay.

I have little to no experience with Motor6Ds, maybe you can port it? The logic must remain the same.

Then you’re missing the multiplication by -1 of the panning of F3 and F4 if they’re numbered left to right.

v.Pan.DesiredAngle = -math.cos((t + c)*2.094)
1 Like

Thank you! https://gyazo.com/6d9b8cad5c15d7ebfbbfc9732ce81992 gyazo crashed while i was recording