dfawertsw
(dfawertsw)
December 31, 2021, 11:07am
#1
I find a script for my character to let his head look at the mouse pointing place.
But the head move so strangely.
This is my script
game:GetService("RunService").Stepped:Connect(function()
local Hit = Mouse.Hit
local Direction = Hit.p + (Hit.LookVector * 5000)
local HumanoidRootPartCFrame = HRP.CFrame
local rotationOffset = (HumanoidRootPartCFrame - HumanoidRootPartCFrame.p):inverse()
PlayerRobot.Torso.Head.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), Direction) * CFrame.Angles(math.pi / 2, 0, 0)
game.ReplicatedStorage:WaitForChild("PlayerHead"):FireServer(PlayerRobot.CamTo,PlayerRobot.Camerasubject)
end)
dthecoolest
(dthecoolest)
December 31, 2021, 11:12am
#2
I believe the reason it is strange also depends on the rig,make sure the Motor6D is connected at the proper location, like for reference for R15, it’s located at the neck:
Here is another method with a different CFrame method for Motor6D or welds you can try out:
I have developed a function to make world space CFrames, like CFrame.lookAt apply when using Motor6D or welds C0 property. This function should work with all rigs as it takes into account of the C1 as explained and derived through here .
I prefer using world space CFrames as it’s easier to visualize rather than thinking in object space relative to the Part0.
local neckJoint = script.Parent
local target = Workspace.Target
local Head = script.Parent.Parent
local upperTorso = neckJoin…
dfawertsw
(dfawertsw)
December 31, 2021, 11:18am
#3
Thank you. I find that my motor6D is at the wrong place