BodyGyro Alternatives

So I have a script that makes a Character face another Character using BodyGyro. However, it just randomly broke and I have no idea what’s going on.

Here is the BodyGyro Instance creation:

local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyGyro.D = 0
bodyGyro.CFrame = newTower.HumanoidRootPart.CFrame
bodyGyro.Parent = newTower.HumanoidRootPart

And the actual turning:

local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame

No errors appear so help would be appreciated.

BodyGyro shouldn’t be used anymore as it is deprecated. Use the new(er) AlignOrientation instead.

I can speak from experience that AlignOrientation does not hold up to BodyGyro.

AlignOrientation is absolutely awful to use for things like vehicles. The movement of it is not smooth at all, when compared to BodyGyro.

Here is my plane system using AlignOrientation,

and here is my plane system using BodyGyro.

The difference is huge.

7 Likes

I hate how they just randomly replaced it, it’s such an unnecessary change and should be reverted. (like a lot of other things)

3 Likes

Hey!
It looks like you had the same problem following GnomeCode’s TDS tutorial as I did.
You can use CFrame.lookAt() as an alternative to BodyGyros. I found this video that explains how that works.

With that knowledge, I wrote the below code for the turning:

-- Replace .PrimaryPart with .HumanoidRootPart if you need to.
tower.PrimaryPart.CFrame = CFrame.lookAt(tower.PrimaryPart.Position, target.PrimaryPart.Position)

Hope this helps :slight_smile:

2 Likes

I tried that! But it looks up and down! I don’t want that! I want it to only look left to right. Can you modify the function to do that or not?

1 Like

Yep! Try this:

tower.PrimaryPart.CFrame = CFrame.lookAt(tower.PrimaryPart.Position, (target.PrimaryPart.Position * Vector3.new(1, 0, 1) + (tower.PrimaryPart.Position * Vector3.yAxis)))

Credit to this post

5 Likes

for this:

bodyGyro.D = 0

ive been wondering what would i repleae this with

2 Likes