Hi. I’m trying to make it where the player faces their mouse upon firing a gun. This is what happens.
My character will continue facing this direction, even after unequipping the weapon.
I tried making the AI (alignorientation) be set to no attachment after 5 seconds, this does not work.
Here’s the code for the AI.
-----------------------------------------------------
--Align character to mouse temporarily.
local Focused = true
task.spawn(function()
while Focused == true do
print("Projected.")
wait()
local pos = Mouse.Target.Position
local unit = (pos - Character:FindFirstChild("HumanoidRootPart").Position).Unit
local direction = Vector3.new(unit.X, Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector.Y, unit.Z).Unit
Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").PrimaryAxis = direction
Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").SecondaryAxis = direction
Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").Attachment0 = Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("AngularAttachment")
end
end)
delay(5, function()
Focused = false
Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").Attachment0 = nil
end)
-----------------------------------------------------
And heres the script for setting up the AI, and the attachment it runs on.
--------------------------------------------------------
--AlignOrientation for tools and stuff
local Align = Instance.new("AlignOrientation")
Align.Mode = Enum.OrientationAlignmentMode.OneAttachment
Align.Parent = char:FindFirstChild("HumanoidRootPart")
Align.Name = "Facer"
local Attachment = Instance.new("Attachment")
Attachment.Name = "AngularAttachment"
Attachment.Parent = char:FindFirstChild("HumanoidRootPart")
Align.MaxTorque = 10000
Align.Responsiveness = 25
--------------------------------------------------------
Any help is appreciated.