#NEED HELP
1 messages · Page 1 of 1 (latest)
So i was using this to turn my char to my mouse pos but it seems ass so i was wondering if theres any better method?
local function RotateToDirection(char, targetPosition)
local hrp = char:FindFirstChild("HumanoidRootPart")
if hrp then
local bg = Instance.new("BodyGyro")
bg.Name = "TempRotation"
bg.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bg.P = 50000
bg.D = 500
bg.CFrame = CFrame.lookAt(hrp.Position, targetPosition)
bg.Parent = hrp
task.wait(0.05)
hrp.Anchored = true
bg:Destroy()
task.delay(3, function()
if hrp and hrp.Parent then
hrp.Anchored = false
end
end)
end
end
local function RotateToDirection(char, targetPosition)
local hrp = char:FindFirstChild("HumanoidRootPart")
local hum = char:FindFirstChild("Humanoid")
if hrp and hum then
local cleanTarget = Vector3.new(targetPosition.X, hrp.Position.Y, targetPosition.Z)
hum.AutoRotate = false
hrp.CFrame = CFrame.lookAt(hrp.Position, cleanTarget)
task.defer(function()
if hum then hum.AutoRotate = true end
end)
end
end```
try this, i had trouble with bodygyro so i switched it to alignorientation
local function RotateToDirection(Char, TargetPos)
local Root = Char:FindFirstChild("HumanoidRootPart")
if Root and TargetPos then
local RootAttachment = Root:FindFirstChild("RootAttachment")
local AlignRot = Root:FindFirstChild("RotateToMouse")
if not AlignRot then
AlignRot = Instance.new("AlignOrientation")
AlignRot.Name = "RotateToMouse"
AlignRot.Mode = "OneAttachment"
AlignRot.Attachment0 = RootAttachment
AlignRot.MaxTorque = math.huge
AlignRot.Responsiveness = math.huge
AlignRot.Parent = Root
end
AlignRot.CFrame = CFrame.lookAt(
Root.Position,
Vector3.new(
TargetPos.X, Root.Position.Y, TargetPos.Z
)
)
return AlignRot
end
return
end
Thanksss it helped me
did it kind of different so it fit better for my project
local function RotateToDirection(Char, TargetPos)
local Root = Char:FindFirstChild("HumanoidRootPart")
local Humanoid = Char:FindFirstChildOfClass("Humanoid")
if not Root or not TargetPos then return end
if Humanoid then
Humanoid.AutoRotate = false
end
local RootAttachment = Root:FindFirstChild("RootAttachment")
if not RootAttachment then return end
local AlignRot = Root:FindFirstChild("RotateToMouse")
if not AlignRot then
AlignRot = Instance.new("AlignOrientation")
AlignRot.Name = "RotateToMouse"
AlignRot.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignRot.Attachment0 = RootAttachment
AlignRot.MaxTorque = math.huge
AlignRot.Responsiveness = 200
AlignRot.RigidityEnabled = true
AlignRot.Parent = Root
end
AlignRot.CFrame = CFrame.lookAt(Root.Position, TargetPos)
return AlignRot
end
local function StopRotate(Char)
local Root = Char:FindFirstChild("HumanoidRootPart")
local Humanoid = Char:FindFirstChildOfClass("Humanoid")
if not Root then return end
local AlignRot = Root:FindFirstChild("RotateToMouse")
if AlignRot then
AlignRot:Destroy()
end
if Humanoid then
Humanoid.AutoRotate = true
end
end