Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the humanoid root part follow the direction of the mouse?

Asked by 6 years ago

t=Instance.new("BodyGyro",script.Parent.Parent.Character.HumanoidRootPart) t.maxTorque = Vector3.new(0,math.huge,0) while true do Character=script.Parent.Parent.Character Player=game.Players.LocalPlayer mouse=Player:GetMouse() Character.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(Character.HumanoidRootPart.Position,mouse.Hit.p)

wait() end

This is what I tried but it makes it rotate slow and it will go to the direction of the mouse but the it will go the fastest route instead of following the mouse exactly.

0
Could you put your code into a code block pleaseee. GottaHaveAFunTime 218 — 6y

1 answer

Log in to vote
0
Answered by
raik220 20
6 years ago

To do this I would use CFrame rather than BodyGyro.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local root = char:WaitForChild('HumanoidRootPart')

local mouse = plr:GetMouse()

game:GetService('RunService').RenderStepped:Connect(function()
    root.CFrame = CFrame.new(root.CFrame.p,root.CFrame.p 
        + Vector3.new(mouse.hit.lookVector.x,0,mouse.hit.lookVector.z))
end)
0
Thanks, could you explain what Renderstepped is while you're at it ;3 Earthkingiv 51 — 6y
Ad

Answer this question