Can AlignOrientation take the place of BodyGyro?

Hey, so I might be looking at alternatives as to how I can rotate and constrain a player model I have to a given direction.

The issue i’m having with BodyGyro, is that it’s very unreliable and delayed when I rotate it to the opposite rotation. Example:

  • I first set the gyro’s CFrame to a rotation of 90 degrees on an axis.
  • After that, I set it’s rotation to -90 degrees on the same axis. This produces a very delayed and glitchy response apparently…

Any ideas for a more reliable workaround? Thanks :slight_smile:

8 Likes

Yes, but the workflow is a lot different. With BodyGyros, you just set the CFrame value and it will rotate the object based on the rotation of that CFrame.

With AlignOrientation, it’s based on attachments. In essence, one attachment tries to match the rotation of the other. However, in order to do this, you have to create a placeholder part in your game to hold the attachments that set the rotation properly. This is kinda weird, but I haven’t found a better way to do it yet.

Here’s what I’ve done:

  1. Create an anchored, invisible, non-cancollide part in the center of your game. Name it something like “AttachmentHolder” or whatever. Make sure the part’s orientation is 0,0,0.
  2. Create your AlignOrientation object in your model
  3. Create 2 attachments. One goes in your model, and the other goes in the AttachmentHolder part.
  4. Set Attachment0 to the attachment in your model, and Attachment1 to the attchment in AttachmentHolder.

Now when you run the game, you can set the orientation of the attachment in the AttachmentHolder and it will rotate your model properly.

For the full picture, here’s a simple script that could set it up:

-- References:
local model = whatever
local attachmentHolder = workspace.AttachmentHolder

-- Create:
local align = Instance.new("AlignOrientation")
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")

-- Assign:
align.Attachment0 = att0
align.Attachment1 = att1

-- Parent:
align.Parent = model.PrimaryPart
att0.Parent = model.PrimaryPart
att1.Parent = attchmentHolder

-- Example to rotate the part:
att1.Orientation = Vector3.new(0, 90, 45)

-- Example to rotate the part using CFrame (for easy compatibility with old BodyGyro systems):
local cf = CFrame.Angles(0, math.rad(90), math.rad(45))
local x,y,z = cf:ToOrientation()
att1.Orientation = Vector3.new(math.deg(x), math.deg(y), math.deg(z))

Below is an example of a part with the necessary components. Try running the game. Then within the AttachmentHolder part, select the single Attachment within it and try setting its orientation. You’ll see the other part in the workspace rotate.

AlignOrientationExample.rbxl (18.8 KB)

36 Likes

Awesome, thank you! I’ll mess around with this. :slight_smile:

1 Like

You can actually parent the extra attachment to workspace.Terrain. This will let you set the CFrame of the attachment to anywhere in the world.

17 Likes

Hey, so I’m trying to use this for a humanoid player model I have, and for some reason, I can’t get the AlignPosition to have any functionality at all…

Not really sure why. I cloned the HumanoidRootPart, welded it to another part in the rig, put an attachment in the HRP, and put another attachment in the newly welded part. I then put an AlignOrientation in the HRP, connecting both of those attachments.

tried messing around with the rotations of the attachments and the AlignOrientation did absolutely nothing :frowning:

Also, upon testing it again, the HRP is starting to respond to the AlignOrientation but no parts in the model are affected by the rotational change…

Any ideas? I thought of maybe using Motor6Ds and using their Angle properties, but I’m not sure how I could get it to rotate on the right axis. I tried this out on the HRP and it rotated in an up/down direction

EDIT: Might’ve found a solution. I just found out “Transform” is a thing with Motor6Ds, and a solution I came up with would be to update that in a tweening function to reach a specified angle, I think that’ll work. If this isn’t an efficient way to do what I’m trying to do or could lead to issues, don’t hesitate to respond. Thanks everyone!

3 Likes