Hello all, I’ve been scripting in the Roblox engine for awhile now, but there’s one area that I have left thoroughly unexplored. CFrame math. Which, I have found by far the most confusing, yet crucial aspect of game development.
The issue in question here relates to continuously rotating the “Waist” Motor found within the players UpperTorso to face the Mouse.Hit LookVector to achieve the effect of the players torso always facing towards the mouse, disregarding player rotation or the cameras positioning. (With some obvious prevention of the player being able to rotate a full 180 degrees to face right behind them)
With some trial and error. This is a very sub-par approach I managed to create:
local NewMouseCFrame = Mouse.hit:ToObjectSpace(Torso.CFrame) local NewTestCFrame=CFrame.new(WaistMotor.Transform.p,NewMouseCFrame.p) local Look = NewTestCFrame.LookVector WaistMotor.C0 = CFrame.Angles(0,Look.X,0)
This is the result. That although looks passable, Has problems such as snapping to positions and the radians switching sides when the player is walking towards the camera. (Player faces opposite to the mouse rather then towards it)
Thank you for taking your time to read this post. I hope that you can help me with this issue.