So, what I’m trying to do is create a dragdetector that can track the value of its rotation.
I’m a new scripter, started maybe like 2-3 weeks ago but I know a bit about math, so I did some research into this, and found (and learnt a bit about) quaternions, gimbal lock and euler rotations.
The orientation system works only in a 180deg region and I can’t really seem to find a way around this.
For reference, I’m trying to make a pepperoni grater, for which every X deg, a pepperoni is made, etc
So, I looked into some documentation about scriptable drag detectors to see if I could make a custom rotation axis one, which I could track angles with directly using quaternions potentially.
I couldn’t find much, but I found a good link for which I tried to understand but scripting is actually hard!!
Anyways, this is as close as I’ve gotten so far, kind of works but not really…
local dragDetector = script.Parent.DragDetector
local handle = script.Parent
local lastViewFrame = CFrame.new()
local function RequestNetworkOwnershipEvent(clickedPart)
local requestNetworkOwnershipEvent = script.Parent:WaitForChild("RemoteEvent")
requestNetworkOwnershipEvent:FireServer(clickedPart)
end
local function rotateHandle(cosAngle)
--local coshalfAngle
--if cosAngle >= 0 then
-- coshalfAngle = math.sqrt((cosAngle + 1)/2)
--else
-- coshalfAngle = -math.sqrt((cosAngle + 1)/2)
--end
--local tanAngle = math.tan(math.acos(cosAngle))
--- Some potential work maybe with cos2x identities?? ^^^
local angle = cosAngle
angle *= 0.5
print(cosAngle)
local quaternion = CFrame.new(handle:GetPivot().Position.X, handle:GetPivot().Position.Y, handle:GetPivot().Position.Z,
math.sin(angle), 0, 0, math.cos(angle)
)
--> Quaternion
handle:PivotTo(quaternion)
end
dragDetector.DragStart:Connect(function(player, ray, viewFrame, hitFrame, clickedPart)
RequestNetworkOwnershipEvent(clickedPart)
end)
local HandleVector = handle:GetPivot().ZVector.Unit
local function getRotatedVector(cursorRay)
local VectorToRay = cursorRay:ClosestPoint(handle:GetPivot().Position).Unit
local VectorsDotProduct = HandleVector:Dot(VectorToRay) -- Magntinudes are 1 so this = cosAngle
rotateHandle(VectorsDotProduct)
end
dragDetector.DragContinue:Connect(function(player, ray, viewFrame)
getRotatedVector(ray)
print("test")
end)
--dragDetector:SetDragStyleFunction(function(cursorRay) --
-- getRotatedVector(cursorRay)
--end)
I get that you could probably do this without local functions and all in 1 go but this was me trying to learn a bit more about how the parameter systems work in functions and such.
So, if anyone has any ideas of how rotations can be tracked in terms of 360deg, whether if it’s with the scriptable DragDetector, or even with the inbuilt RotationAxis one, that would be amazing.
Edit:
^^ This was my thought process behind it