Hi, I’m trying to rotate a dummy to look at the character’s head. I’m using CFrame.new() to rotate it, but it’s not working for some reason, Here’s my code:
RunService.RenderStepped:Connect(function()
if dummy:FindFirstChild("HumanoidRootPart") then
dummy.HumanoidRootPart.CFrame = CFrame.new(dummy.HumanoidRootPart.Position, Vector3.new(head.Position.X, head.Position.Y, 0))
end
end)
A video of the dummy when I try to rotate it and with CFrame.new(dummy.HumanoidRootPart.Position, head.Position) https://streamable.com/gfujoz
There is no fix for this problem and you will most likely simply need to avoid having it look directly on the Y axis. This is because .lookAt using the “up” vector to cross vectors (V3:Cross(Up)) to get the resulting matrix.
You need to check if the direction to the target is close to parallel with the Y axis.
local target = head.Position
local dir = (target - dummy.HumanoidRootPart.Position).unit
local dot = dir:Dot(Vector3.new(0,1,0))
if (dot >= 0.9) then
target -= Vector3.new(0,2.5,0)
elseif (dot <= 0.9) then
target += Vector3.new(0,2.5,0)
end
dummy.HumanoidRootPart.CFrame = CFrame.lookAt(dummy.HumanoidRootPart.Position, target)
I don’t want the rotation to happen like this. It’s just looking at my character right away. My code was doing the exact some job, I want something to happen like this:
I have 0 idea what you are trying to say and what you mean with just “Y rotation.” Also you just showed me a picture so I don’t know what I’m supposed to take from that. Do you mean just rotation around the Y axis like shown below?
It is because you welded the other BodyParts to the head, or the Motor6Ds are all towards the head.
Try to apply all welds to the HumanoidRootPart, or all Motor6Ds.
(I am unsure what you are using, that is why I say both)