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

Issues with using Body Gyro on Players?

Hello everyone! What I am trying to do is get the player face where the mouse cursor is. I am able to do this with using the players position, but of course it isn't very smooth, so i am trying to use BodyGyro. Whenever i attempt the even though the bodygyro's CFrame is changing the character doesnt move at all, and im not sure what the problem is. Here is my code:

local RunService = game:GetService("RunService")

local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local Root = script.Parent:WaitForChild("HumanoidRootPart")
local Gyro = Instance.new("BodyGyro", Root)


local function onRenderStep()
	Gyro.CFrame = CFrame.new(Root.Position, Vector3.new(Mouse.Hit.p.X, Root.Position.Y, Mouse.Hit.p.Z))
end

RunService:BindToRenderStep("Character", Enum.RenderPriority.Character.Value, onRenderStep)

Using the root part's position to turn the player works, but bodygyro doesn't. please let me know if someone knows how to fix this!

2 answers

These body forces do not work very well when the player is grounded. You might see it working if you run it while in air. I suggest you to change root's CFrame directly.

3 comments

0

ah i see, i have jumping disabled so i didnt realize this could be an issue. I'll see if there is any way to bypass this

0

After turning on jumping the body did not turn even off of the ground, so this doesn't appear to be the issue.

0

Also, like i said, changing the root's cframe directly works perfectly on the client, but for other players and different server events it isnt smooth and causes issues, hence me looking for a smoother alternative. If you know of something other than BodyGyro and not the root's CFrame, please let me know!

I have found a solution for anyone suffering the same problem:

Make sure you define the other aspects of the BodyGyro when creating it in the script.

adding

Gyro.D = 40
Gyro.P = 10000
Gyro.MaxTorque = Vector3.new(4000000, 4000000, 4000000)

to the script solved my issue.

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