Align Orientation Issues

Hello, I’m having an issue with in a script with Align Orientation. I’m trying to make a tower defense game. When a tower tries to shoot an enemy, it turns towards the enemy and shoots it.

I have the damage working well, but my problem is that the tower isn’t turning toward the enemy.

Script:

function tower.Attack(newTower)
	local target = FindNearestTarget(newTower)
	if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
		local targetPosition = target.HumanoidRootPart.Position
		
		local alignOrientation = newTower:FindFirstChild("AlignOrientation")
		if alignOrientation then
			alignOrientation.LookAtPosition = Vector3.new(targetPosition.X, 0, targetPosition.Z)
		end
		
		animateTowerEvent:FireAllClients(newTower, "Attack")

		target.Humanoid:TakeDamage(25)
	end

	task.wait(1)

	tower.Attack(newTower)
end

Any help would be greatly appreciated!

2 Likes

Make sure that the properties mode and alignType are set to OneAttachment and PrimaryAxisLookAt if they aren’t already. Then just put an attachment inside the part you need to rotate around (you made need to adjust the rotation so the yellow arrow is pointing towards the front of the object), and you’re current code should work fine.

I would recommend not using physics based rotation if its not necessary and instead doing based around CFrames:

game:GetService("RunService").PostSimulation:Connect(function()
    towerPart.CFrame = CFrame.lookAt(towerPart.CFrame, enemy.CFrame)
end)

I’m not finished coding it yet, but this seems like the best option, thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.