I’m creating a turret system. I’m trying to keep it as efficient as possible:
Should I have the turrets target their enemies each in an individual script, or somehow (help, please?) set all the turrets nearby targets under one handler.
I know this is vague, but it’s not a difficult topic, I guess?
Periodically check if the turret can see targets. If it sees a target, use align orientation to set its pose to look at the target CFrame.new(turret.Position, target.Position). Also when you do this form a line from them and then make the y value the same as the turrets position y value. Get the angle difference between these two lines and take the absolute value. That’s your error. Then check, again, periodically, if this error is like 0.5 degrees off. Once it reaches that do a debounce and fire a bindable event that does whatever you want to it. Have an attribute that is used to debounce so the event can then set the turret to be activated again. If it doesn’t see it just set the align orientation to be the current pose. If it sees multiple targets just focus on the first one it saw by using a list of targets in sight and then when it loses one player or whatever it rotates the items in the list to the left. This will allow you to use collection service to have this be in one script