Math stuff Help!

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

1 Like

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.

1 Like

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

1 Like

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

1 Like

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 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)
``````
2 Likes

You will need to use a CFrame.lookat() and use some math to change it from global space to local space

1 Like

how do i limit it, i try using math.clamp but i can still turn 180 degrees despite limit to 45

1 Like

Math.clamp should work. Just make sure to work with the objectspace CFrame and make sure the angles units are in radians.

1 Like

i did what you did but it doesnt limit?

``````-- services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

-- variables
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local function SetCharacter(Char)
Character = Char
end

if Player.Character  then
SetCharacter(Player.Character)
end

-- 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

Neck.C0 = Neck.C0 * CFrame.fromOrientation(x, y, z)
wait(0.1)
end)
``````

Should be like this:

``````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