How to clamp a cframe?

Ok hello. My name is Herobrinekid1. And i have been trying to make an eye ball model that will follow the players torso. But i don’t know how to make it clamp at 49 angles… I have tryed different methods and watched some youtube videos. But nothing works. So i thought maybe someone could help here. I can include small clips if that’s needed

Here is my code:

You could use this class here and only clamp the values when you create a new CFrame:

local CFrame = require(CFrameClassLinkThatYouConvertInAModuleScript)

Or just clamp the CFrame components and create a new CFrame with the clamped values:

local Table = {}
for _,component in ipairs(YourNormalCFrame:components) do
    table.insert(Table, #Table+1, math.clamp(component))
end

local YouClampedCFrame = CFrame.new(Table[1], Table[2], Table[3], and etc.)

But remember that a CFrame stores a rotation, so what you are trying to do may cause your base part to rotate in an unwanted rotation.

And i still now understand why you want to clamp this to 49 degrees

1 Like