There are rotating turrets that the player can rotate. The turret rotation uses Motor6Ds, and changing the Y rotation on C1 will make it rotate around a base.
The player is supposed to be able to click to a point and the turret should then face towards where the player clicked. This could hypothetically be done using CFrame.lookAt()
, but this is not possible with a Motor6D.
I need to be able to find the rotation needed to apply to the Motor6D’s C1 for the turret to face towards where the player clicked.
Client script:
Mouse.Button1Down:Connect(function()
Event:FireServer("Aim",Mouse.Hit.Position)
end)
Server script:
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player,control,Position)
if control == "Aim" then
for _, Turret in Main:GetChildren() do
if Turret.Name == "Turret" then
Turret.Rotate.Motor6D.C1 = CFrame.lookAt(Turret.Rotate.Position,Vector3.new(Position.X,Turret.Rotate.Position.Y,Position.Z))
end
end
end
end)
I knew when writing this that the Server script wouldn’t work, but I wanted to see if I could understand a little more before trying to do this; the script does absolutely nothing in helping me find out what else to do.