How to make Motor6D's Part1 look on the another part?

How do I make Motor6D’s attached part be faced to another part? (something like Team Fortress 2 sentry)
Sentry has a Humanoid and a Torso anchored (this doesnt seem to change anything, though)

I have tried to do it through CFrame.lookAt. It somewhat works at first frame, but then only follows the target very, very briefly.


The current code I have:

local Character = script:FindFirstAncestorOfClass("Model") --Sentry model
local Attacking = workspace.Part -- This is for an example, Attacking varies in the rest of a script
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
    Character.Head.Neck.C0 = CFrame.lookAt(Character.Head.Neck.C0.Position, 
    Attacking.PrimaryPart.Position) * CFrame.Angles(math.rad(-90), 0, math.rad(-90))
end)

Things I tried (and they obviously didnt work):

  • Setting CFrame.lookAt to a Part and not Motor6D (turret starts jumping like crazy)
  • Setting C1 instead of C0 (no result)
  • Setting Head Position in CFrame.lookAt instead of Character.Head.Neck.C0.Position (sentry loses its head l el)
1 Like

You don’t really need to modify Moto6D’s. Something like

 TurretHead.CFrame *= CFrame.lookat(Vector3.zero, Enemy.PrimaryPart.Position)

should work. I don’t know why it didn’t work for you previously.

Actually, This is incorrect. here’s the proper way to do it:
TurretHead.CFrame = CFrame.lookat(TurretHead.CFrame.Position, Enemy.PrimaryPart.Position)

Here’s how it should look:

Do this and you should probably remove the motor6d

Already tried the second one, the sentry starts jumping around (I’m not joking xd :sob:)
About the first one, the sentry starts acting like this:

External Media

(if the link does not work: starts rotating on all axis like crazy)

Motor6d is being used for animation. Is there an alternative?

did you try anchoring the primary part?

1 Like

Just tried, this one works. Much gratitude.