How do i rotate 90 degrees correctly?

I can’t seem to figure out how to rotate my eyeball correctly, im basically trying to make it move and rotate 90 degrees each time but every time i do it it does a spin, i just want it to turn correctly instead of spinning.

RobloxStudioBeta_7fIniU5QHS

local rot = Vector3.new(0, 0, 0)

function nextPointMove()
	local points = {workspace.Position1, workspace.Position2, workspace.Position3, workspace.Position4}
	local currentPoint = nil
	local nextPoint = nil
	for _,point in pairs(points) do
		if currentPoint == nil then currentPoint = points[1] end
		if currentPoint == point then
			if num == 5 then
				nextPoint = Vector3.new(points[1].Position.X, handle.Position.Y, points[1].Position.Z)
				num = 1
			else
				nextPoint = Vector3.new(points[num].Position.X, handle.Position.Y, points[num].Position.Z)
				num += 1
			end
			currentPoint = Vector3.new(point.Position.X, handle.Position.Y, point.Position.Z)
			moveToPoint(nextPoint)
			rotateHandle(rot)
			rot = Vector3.new(0, (rot.Y - 90), 0)
		end
	end
end
3 Likes

Why not make it rotate as a snap and then tween that change with TweenService?

If you need to rotate exactly 90 degrees each time, I would recommend taking the current CFrame of the eye and simply multiply it by CFrame.Angles(0,math.pi*.5,0), which is 90 degrees on the local Y axis of the eye.

However, if you want a more dynamic system, I recommend using the position part’s orientation so you can be more flexible.

See this example:
eyefollowpath

I added decals on the parts to show the way they face.
Here is my code used to do this:

task.wait(3)

local TS = game:GetService("TweenService")

local eye = script.Parent

local points = {workspace.Position1, workspace.Position2, workspace.Position3, workspace.Position4}

local function move(A,B)
	eye.CFrame = A.CFrame * CFrame.Angles(0,math.pi*.5,0) + Vector3.new(0,3,0)
	local tween = TS:Create(eye, TweenInfo.new((A.Position-B.Position).Magnitude*.2, Enum.EasingStyle.Linear), {
		CFrame = B.CFrame + Vector3.new(0,3,0)
	})
	tween:Play()
	tween.Completed:Wait()
	local rotation = TS:Create(eye, TweenInfo.new(.1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
		CFrame = B.CFrame * CFrame.Angles(0,math.pi*.5,0) + Vector3.new(0,3,0)
	})
	rotation:Play()
	rotation.Completed:Wait()
end

while true do
	for i, v in pairs(points) do
		local destination = i < #points and points[i+1] or points[1]
		move(v, destination)
	end
end

Obviously you can tweak this to suit your needs, but the idea is that it follows the path based on the orientation of the parts and at the end of its movement, it will rotate by 90 degrees.

1 Like

maybe just simply try to change the " -90 " to " - 270"

Rotate the eyes CFrame
e.g

--If you use the eyeball pupil as front moving part make sure the pupil of your eyeball is facing to LookVector (Front) Direction
local eye = workspace.Eye -- Eye Part
eye.CFrame = eye.CFrame * CFrame.Angles(0,math.rad(-90),0)

-- Using math.rad() converts degrees into Radians 
-- Remove the minus(-) to make part rotate opposite direction

Before
After
Example Rotate 90 Degrees.rbxl (34.5 KB)

1 Like