I use this code to control the hoverboard rotation in my game. The default state is actually perpendicular to the camera because of how the hoverboard needs to sit. The issue is that when Y is changing from less than to more than or vice versa, the board will get stuck in a feedback loop of trying to switch between control states. Is there a way to fix this using dot or cross?
local x, y, z = camera.CFrame:Inverse():ToEulerAnglesXYZ()
local _,Y,_ = hrp.CFrame:ToEulerAnglesXYZ()
if Y > 0 then
-- Camera is looking "backward", flip the controls
if uis:IsKeyDown(Enum.KeyCode.A) then
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(135), z)
elseif uis:IsKeyDown(Enum.KeyCode.D) then
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(45), z)
elseif uis:IsKeyDown(Enum.KeyCode.S) then
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(270), z)
else
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(90), z)
end
else
-- Camera is looking "forward"
if uis:IsKeyDown(Enum.KeyCode.A) then
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(45), z)
elseif uis:IsKeyDown(Enum.KeyCode.D) then
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(135), z)
elseif uis:IsKeyDown(Enum.KeyCode.S) then
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(270), z)
else
torque.CFrame = camera.CFrame * CFrame.Angles(x, math.rad(90), z)
end
end