Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use BodyGyro's to rotate Characters?

Hello there, I am working on a Tool which makes the Character to turn to the place that his mouse hits if that object that his mouse hits parent has a Humanoid inside of it called "Humanoid" then it will turn that way that's basically what I want to achieve at the moment... This is my script don't worry about most of the other things everything works except the BodyGyro part....

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent

tool.Activated:connect(function()
	local ray = Ray.new(
		tool.Handle.CFrame.p,
		(mouse.hit.p - tool.Handle.CFrame.p).unit * 999999999999
	)
	local ignore = player.Character
 	local hit, position, normal = workspace:FindPartOnRay(ray, ignore)
    local hum = hit.Parent:findFirstChild("Humanoid")
    if hum then
	local torso = player.Character:WaitForChild("Torso")
	local torso2 = hit.Parent:WaitForChild("Torso")
	local bg = Instance.new("BodyGyro", torso)
	bg.D = 300
	bg.P = 300000
	bg.MaxTorque = Vector3.new(400000000, 0, 400000000)
	bg.CFrame = torso2.CFrame
	game.Debris:AddItem(bg, 5)
	end
end)

The BodyGyro goes to my Torso however, the Character won't rotate... And the reason I think BodyGyros are used for rotation is because I asked a lot of people as to how they rotated the Character with a Body Mover and they answered "BodyGyro" so.... I tested it. I hope someone can help me out I am a bit new to these BodyMovers.

1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent

tool.Activated:connect(function()
    local ray = Ray.new(
        tool.Handle.CFrame.p,
        (mouse.hit.p - tool.Handle.CFrame.p).unit * 999999999999
    )
    local ignore = player.Character
    local hit, position, normal = workspace:FindPartOnRay(ray, ignore)
    local hum = hit.Parent:findFirstChild("Humanoid")
    if hum then
    local torso = player.Character:WaitForChild("Torso")
    local torso2 = hit.Parent:WaitForChild("Torso")
    local bg = Instance.new("BodyGyro", torso)
    bg.D = 300
    bg.P = 300000
    bg.MaxTorque = Vector3.new(400000000, 400000000, 400000000)
    bg.CFrame = CFrame.new(torso.Position - Vector3.new(0,torso.Position.y,0),torso2.Position - Vector3.new(0,torso2.Position.y,0)) --remove y value so character is always upright
    game.Debris:AddItem(bg, 5)
    end
end)

You've got the right idea. It's as simple as changing line 20 & changing y-torque, but you might need to increase the value of P.

2 comments

0

Do you have any idea as to how I would make the character rotate smoothly 360 degrees using a Body Gyro?

0

You mean rotate constantly in a circle, or just once?

This discussion is preserved as it was. New answers, comments, and votes are closed.