Been experimenting with CFrame and attemting to learn more about trigonometry, I still don't get what sin, cos, and tan does, these three functions are wonderful.. I hope I can figure out someday soon.
Anyways, since manipulating the Coordinates of the HumanoidRootPart's "RootJoint" can rotate the character at a desired angle, I am trying to rotate the character via the Z Angle relative to the mouse, so it looks like the character is looking at the direction the mouse is pointing at, just the Z axis angle, because if I put X and Y it would tilt like a freakin' maneuver plane.
This is my attempt, it works, but it's not accurate, it's slightly offset.. and i'd love to learn how to actually do it via math/trigonometry.
local p=game:GetService("Players").LocalPlayer local m=p:GetMouse() repeat wait() until p.Character local c=p.Character local t=p.Character:WaitForChild("HumanoidRootPart") local Root=t:WaitForChild("RootJoint") m.Move:connect(function() local CF=CFrame.new(t.Position,m.Hit.p):toObjectSpace(t.CFrame*Root.C0) local _,_,_,_,_,_,_,_,_,x,y,z=CF:components() Root.C1=CFrame.Angles(math.rad(-90),0,math.rad(180)) *CFrame.Angles(0,0,math.atan2(math.cos(z)*math.sin(x),math.sin(y))) end)
Professional help is greatly appreciated, thank you!