How to stop Body Gyro from facing Y

I attached a Body Gyro to my characters HumanoidRootPart to make them face the direction their mouse is pointing. But I only want them to face the X and Z Axis and leave the Y Axis the same.

Script:

local ATKGyro = Instance.new("BodyGyro")
	ATKGyro.Parent = char.HumanoidRootPart
	ATKGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	ATKGyro.D = 100
	ATKGyro.P = 10000
	ATKGyro.CFrame = Mouse.Hit

Video:

For the MaxTorque try this:

ATKGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)

Alternatively you can adjust the CFrame to stay in the XZ plane before setting it to the BodyGyro’s CFrame.

I tried this and it doesnt seem to do anything. Heres a video of what happens:


(When I attack, it doesnt face the direction im aiming)

try replacing this

ATKGyro.CFrame = Mouse.Hit

with this:

ATKGyro.CFrame = CFrame.new(Mouse.Hit.Position * Vector3.new(1, 0, 1))

Multiplying it by Vector3.new(1, 0, 1) removes the Y component by making it 0 and keeps the X and Z components the same. (then you have to turn it back into a CFrame using CFrame.new())

You have to put a loop around where you set the CFrame.

When you construct a CFrame using the single Vector3 argument it’s orientation defaults to 0, 0, 0.

ATKGyro.CFrame = CFrame.new(Vector3.new(0, 0, 0), Mouse.Hit.LookVector * Vector3.new(1, 0, 1))

Since position doesn’t matter for bodygyros, they can just use the LookVector

1 Like