Hello reader!
I believe I’m using Quenty’s spring and I’m making a sort of viewmodel item thing. Which will have a part be offset in front of the player’s camera to the right slightly. Here is a video of it;
As you see it sorta freaks out and spins around a bunch. Through research, I have found this is what is known as gimbal locking
. According to my research, it’s caused when two axi’s of Euler angles line up it tries to free itself from this locking
by spazzing out and finding the quickest path from a to b. The solution is to switch to rotating it by quaternions since they operate in 4d space but can be used in 3d space. The problem is I do not really understand quaternions in the slightest, but I am hoping someone can help me to a solution. My code goes like this;
local function update()
local tool = workspace.MyTool
--//Calculate the goal cframe
local goal_cframe = camera.CFrame:ToWorldSpace(offset)
--//Linearize the goal cframe
local goal_pos, raw_goal_ang = getPositionAndAnglesFromCFrame(goal_cframe)
--//Set the springs' target's
spring_pos.Target = goal_pos
spring_ang.Target = raw_goal_ang
--//Set some variables for their position's
local tool_pos = spring_pos.Position
local tool_ang = spring_ang.Position
--//Create the final goal cframe
local final_camera_cframe = getCFrameFromPositionAndAngles(tool_pos, tool_ang)
--//Set the tools cframe
tool.CFrame = final_camera_cframe
end
Any help would be greatly appreciated!