AlignOrientation on Character doesn't face correct direction

I am using ‘AlignOrientation’ on my character to allow the character to rotate towards the cursor. The issue I am having is that while it rotates it is not facing the correct direction.

local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment

alignOrientation.Attachment0 = RootPart.RootRigAttachment

alignOrientation.MaxTorque = 10000

alignOrientation.Responsiveness = 25
alignOrientation.Parent = RootPart

RunService.RenderStepped:Connect(function()
	local pos =  Mouse:Project(150) --returns world position from mouse position w/ distance as the arg.

	local unit = (pos - RootPart.Position).Unit
	local direction = Vector3.new(unit.X, RootPart.CFrame.LookVector.Y, unit.Z).Unit
	alignOrientation.PrimaryAxis = direction
	alignOrientation.SecondaryAxis = direction
end)

As you can see from this short GIF the rotation is clearly not as desired.

https://gyazo.com/ecdab20a225d3f9850651bc2e64731ed

If anymore information is needed please don’t hesitate to ask!

It appears it’s just 90 degrees out.
Have you tried adding or subtracting 90 degrees from the y value in direction?

I have not, I can’t say I’m familiar with adding/subtracting by degrees on a unit vector.

You can just add Vector3 values as shown here: Vector3 | Roblox Creator Documentation
I’m not really familiar with Vector3s, but I think you can also just do RootPart.CFrame.LookVector.Y + 90 or maybe + math.rad(90) for radians instead of degrees.

1 Like

Thanks for the idea, I came up with a solution. The front of the Attachment was pointing to the right. So my solution was creating an attachment and orientating it by 90 on the Y. Now the attachment is pointing forwards, removing the offset previously causing me issues.

1 Like