I have a local script that allows the right arm to follow the player’s mouse movements. I’d also like to keep track of the orientation of the arm relative to the character. I need to track this because I’d like to add some restrictions or features when the arm is in a certain orientation. This is my script that fires every heartbeat:
local NewCFrame = CFrame.new(Character.UpperTorso.Position, Mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
local NewCFrame = RightArmOffset * Character.UpperTorso.CFrame:toObjectSpace(NewCFrame)
RightArmWeld.C0 = NewCFrame
This is my current solution for tracking the arm:
Local Script:
local ArmDirection = DataHandler.FindDirection({NewCFrame:ToEulerAnglesXYZ()})
Module Script:
local Directions = {
--X,Y,Z
["Front"] = {{90,0,0}},
["Up Front"] = {{180,0,0}},
["Down Front"] = {{0,0,0}},
["Back"] = {{90,0,-180},{90,0,180}},
["Up Back"] = {{0,0,-180},{0,0,180}},
["Down Back"] = {{180,0,180},{180,0,-180}},
["Left"] = {{90,0,-90}},
["Down Left"] = {{90,90,-90}},
["Up Left"] = {{90,-90,-90},{90,-90,90}},
["Right"] = {{90,0,90}},
["Down Right"] = {{90,-90,90}},
["Up Right"] = {{90,90,90}},
}
function DataFunctions.FindDirection(Data)
local function DirectionFormat(Num)
return RoundToNearestMultiple(FormatDegree(Num),90)
end
local x = DirectionFormat(Data[1])
local y = DirectionFormat(Data[2])
local z = DirectionFormat(Data[3])
for Direction,Possibility in pairs(Directions)do
for i, Angle in ipairs(Possibility) do
local X = Angle[1]
local Y = Angle[2]
local Z = Angle[3]
if x == X and y == Y and z == Z then
return Direction
end
end
end
return "Direciton Not Found"
end
I had to list out every possibility for each direction, this may not be the most effective method. My knowledge of trigonometry is also not too concrete.
Here is a video of it:
If anyone has a more effective way of scripting this, please let me know. I appreciate you reading this c: