I have a viewport object and a character inside the viewport along with a script I have written to rotate the character’s head towards the mouse point on screen. Only problem is for whatever reason the character will not do this when I try and use this technique on Motor6D.
This is the script
local mouse = game.Players.LocalPlayer:GetMouse() local viewport = script.Parent.ViewportFrame local visualOffset = 20 local char = viewport.viewportTest local head = char.Head while true do local viewSizeX = mouse.ViewSizeX local viewSizeY = mouse.ViewSizeY local direction = ((viewport.AbsolutePosition + viewport.AbsoluteSize/2) - Vector2.new(mouse.X, mouse.Y)) * .05 local finalDirection = Vector3.new(direction.X,direction.Y,-visualOffset) + head.Position head.Neck.C0 = CFrame.new(head.Neck.C0.Position,finalDirection) game:GetService("RunService").RenderStepped:Wait() end
How it works is I get the position of the viewport’s center and then the position of the mouse, downsize it, then translate it to real world space with a Z offset. I then set the CFrame of the C0 property of the neck joint to be itself looking at the position of the mouse translated to real world space. Then waits renderstep to make sure this is done before the render update. Instead of the expected behavior the joint doesnt rotate at all.
I’m not sure what’s wrong here, any help? Thank you for your time