Help making Motor6D face mouse position

I want my character to look exactelly where the mouse pointer is facing.
I made it susessfully look BUT there is a situation where it bugs, usually when X is too high near 1 or -1, look it in the video.

The redbar show where its actually pointing from Waist.C0.Position

(When it faces a bit to the side is because of the idle animation playing)

My current mover function is this one:

local Waist = _G.UpperTorso:WaitForChild("Waist")
local WaistC0 = Waist.C0

Solver = function()
	local RootCam = CFrame.lookAt(_G.zero, (_G.Mouse.Hit.Position - 
_G.Root.Position)):VectorToObjectSpace(_G.Root.CFrame.LookVector)
	Waist.C0 = CFrame.lookAt(WaistC0.Position, WaistC0.Position + Vector3.new(-RootCam.X, 
RootCam.Y * math.sign(RootCam.Z), RootCam.Z))
end

Pretty sure that’s because of Gimbal Lock. This helps explain a bit about it:

1 Like
local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local UpperTorso = Character:FindFirstChild("UpperTorso") or Character:WaitForChild("UpperTorso")
local Waist = UpperTorso:FindFirstChild("Waist") or UpperTorso:WaitForChild("Waist")

local function OnRenderStep()
	Waist.C0 = CFrame.lookAt(Waist.C0.Position, Mouse.Hit.Position) 
end

RunService.RenderStepped:Connect(OnRenderStep)

Motor6Ds have limits in the amount they can rotate.

1 Like