What I want to achieve
I am trying to make the y axis of the rootjoint motor6d match the camera’s y axis so that the player auto rotates parallel with the camera
-As you can see in the video the character is spinning when colliding another part
What solutions have I tried so far?
I have tried making the C0 of the RootJoint match the humanoidrootparts orientation but that didnt really do anything.
–Client code inside of the character (the remote is just the same code just to sync)
local camera = workspace.Camera
local humanoidrootpart = script.Parent.HumanoidRootPart
local remote = game.ReplicatedStorage.Autorotate
game:GetService("RunService").Heartbeat:Connect(function()
local cframe = camera.CFrame
local x,y,z = cframe:ToOrientation()
local orientation = Vector3.new(0,math.deg(y),0)
remote:FireServer(orientation)
local rootJoint = humanoidrootpart and humanoidrootpart:FindFirstChild("RootJoint")
rootJoint.C0 = CFrame.fromOrientation(0, humanoidrootpart.Orientation.Y /-1,0)
rootJoint.C1 = CFrame.fromOrientation(0,-y,0)
end)
Use AlignOrientation with to avoid that conflict between the script and Roblox collision system
And there is no need constantly fire the orientation to server when using AlignOrientation
I have already tried this and this issue kept happening so I switched to script based. (Im also using unreliable remote events so it doesn’t mess up performance)
local modelChar = script.Parent
local ao = Instance.new("AlignOrientation", modelChar)
ao.Mode = Enum.OrientationAlignmentMode.OneAttachment
ao.Attachment0 = modelChar.PrimaryPart:FindFirstChildOfClass("Attachment")
ao.Responsiveness = 50
local camera = workspace.CurrentCamera
function NormalizeAngleRad(intAngleRad :number)
return (intAngleRad+math.pi) % (math.pi*2) - math.pi
end
local function UpdateLook()
local vec3CameraLook = camera.CFrame.LookVector
local numRadAngle = -math.atan2(vec3CameraLook.Z, vec3CameraLook.X) - math.pi/2
local numRadCorrectAngle = numRadAngle
ao.CFrame = CFrame.Angles(0,numRadCorrectAngle,0)
end
camera:GetPropertyChangedSignal("CFrame"):Connect(UpdateLook)