AlignOrientation not working on parts welded to anchored ones

  1. What do you want to achieve?
    I just want to create a basic turret that uses AlignOrientation to point the base at the target’s X axis, and another one that rotates the secondary part to point at the target’s Y and Z axis.

  2. What is the issue?
    After some time, I realized the AlignOrientation does not work because the turret’s base is linked to an anchored plate. Is there any way to get around this?


    (picture of the turret for reference)

  3. What solutions have you tried so far?
    I tried un-anchoring the plate, but it just makes the entire turret fling and the AlignOrientation doesn’t work. I tried fiddling with the AlignOrientation’s CFrames, and I don’t want to switch just having the parts’ CFrames snap because it looks unpolished. I triple checked the target is present in the workspace, so the turret does have something to look at.

function module.TurnLauncher(basePart, railPart, targetPosition)
	basePart.AlignOrientation.CFrame = CFrame.lookAt(basePart.Position, Vector3.new(targetPosition.X,0,0))
	railPart.AlignOrientation.CFrame = CFrame.lookAt(railPart.Position, Vector3.new(0,targetPosition.Y,targetPosition.Z))
end

(The code if it helps)

Hello! I have a potential solution for you called CFrame.fromMatrix I use these a lot in situations such as this.

Basically it requires the position, upvector, rightvector, and -lookVector components of your isntance, but you can set the lookvector freely whilst keeping all else the same! Therefore circumventing using align orientation.

Hopefully this helps!

Also, here is a snippet of code I sampled from my game so you can have an easier time here.

local pos = Vector3.new(data[3], data[4], data[5])
local lookVector = Vector3.new(data[6], data[7], data[8])
local upVector = Vector3.new(data[9], data[10], data[11])
local rightVector = lookVector:Cross(upVector)

local newCFrame = CFrame.fromMatrix(pos, rightVector, upVector, -lookVector)

This is very helpful, and I thank you for it, but I need to have some way of smoothly turning the turret. What I meant by “getting around this” is maybe finding a setting or some other way of building the turret so it still turns smoothly and consistently while looking at a moving target or moving from its starting position.

you can use tweenservice and set this CFrame as your destination CFrame and it should smoothly turn the turret.

If you’re moving the turret you could probably just keep updating the tween destination and it should correct and just keep moving to its new destination while you’re moving the turret.

Also, if you want to stick with align orientation you would have to make a non rigid connection to the anchored base since alignorientation uses torque which cannot be applied to an instance that is immovable due to rigid connection to an immovable instance.