I only know middle school math for an obvious reason but I want to make my characters head move to point at player cursor.
I thought of how the C0 will be 0, 0, 0 despite the orientation of the character and how Cframe:lookat() will only work for things on the base axis. So I thought of subtracting the heads orientation from the C0 orientation and then adding the CFrame:lookat() value to the C0 orientation. I tried this in command bar and it give error about the orientation value needing to be a vector3. I just want to know if my idea would work in the first place to be honest. Thanks
CFrame:lookat() uses either a CFrame or a Vector3, don’t know which because I don’t use these often. Look up “how to point part towards something roblox” and find some help pages/video tutorials, I’m sure there are quite a few on this.
The thing with using a neck’s motor6d is that the orientation is on its own axis so I was wondering if subtracting the orientation of the character’s head from the motor6d c0 orientation would result in the head’s physical rotation would be equal to something with an orientation of 0, 0, 0 in the normal axis
This is why I can’t just use CFrame:lookat() because it will return a value that would only work on a normal axis which is why I want to know if my idea of cancelling out the orientation to look like 0, 0, 0 and then adding the CFrame:lookat() value to the orientation would work
Motor6Ds are just an offset value, they are in local space/object space; you have to create a world space CFrame and then translate that to object space then apply it to the neck c0
Of course… you can add angle limits
local roblox = workspace.Roblox
local neck = roblox.Head.Neck
local block = workspace.block
game:GetService("RunService").Heartbeat:Connect(function(dt)
local objectspace = neck.Part0.CFrame:ToObjectSpace(CFrame.lookAt(neck.Part0.Position, block.Position))
neck.C0 = CFrame.new(neck.C0.Position) * objectspace
end)
-- services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- variables
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character, Neck, Head
local function SetCharacter(Char)
Character = Char
Head = Character:WaitForChild("Head")
Neck = Head.Neck
end
if Player.Character then
SetCharacter(Player.Character)
end
Player.CharacterAdded:Connect(SetCharacter)
-- code
RunService.RenderStepped:Connect(function()
local ObjectSpace = Neck.C0:ToObjectSpace(CFrame.lookAt(Neck.C0.Position, Mouse.Hit.Position))
local x, y, z = ObjectSpace:ToOrientation()
-- limit rotation
x = math.clamp(x, math.rad(-45), math.rad(45))
y = math.clamp(y, math.rad(-45), math.rad(45))
z = math.clamp(z, math.rad(-45), math.rad(45))
Neck.C0 = Neck.C0 * CFrame.fromOrientation(x, y, z)
wait(0.1)
end)
RunService.RenderStepped:Connect(function()
local ObjectSpace = Neck.Part0.CFrame:ToObjectSpace(CFrame.lookAt(Neck.C0.Position, Mouse.Hit.Position))
local x, y, z = ObjectSpace:ToOrientation()
-- limit rotation
x = math.clamp(x, math.rad(-45), math.rad(45))
y = math.clamp(y, math.rad(-45), math.rad(45))
z = math.clamp(z, math.rad(-45), math.rad(45))
Neck.C0 = CFrame.fromOrientation(x, y, z) + Neck.C0.Position
end)