Currently, the rotation of the turret is handled via CFrame whenever the player holds F, to fire the gun.
local lookVector = Vector3.new(MousePos.X,Part.CFrame.Y,MousePos.Z)
Part.CFrame = CFrame.new(Part.CFrame.Position,lookVector)
It works fine when it’s not mounted to a moving base. It starts to spaz out when it’s on a moving platform, however, as shown below.
The base of the boat is being moved by a BodyVelocity. This image also shows how they are connected:
It probably has to do with NetworkReplication. If the movement is happening in the server, then the platform is probably ahead in the server than in the client so it looks like that. If the gun’s NetworkOwner is the player, then that could be the reason as well. I am not entirely sure, but from my perspective, it looks like a NetworkReplication problem.
Yup that is the issue. The movement is handled via the server.
Client: Left side | Server: Right side
Replicate the movement on the client, then have the server update what position the turret is at every few seconds. If you want it to look smooth, have the turret tween on the server. Here’s a video from @okeanskiy
This will also prevent any lag coming from the turrets in the long run.
If the object is to be used by a single person, then messing around with NetworkOwnership would be the way to go in my opinion. If it is to be used by many, then replicating the movement on the client like @Afraid4Life mentioned would be the best option. I’ve seen many games replicate movements on the client and then update the server occasionally. It all depends on what the use of it is. I am not really the best when it comes to replicating since I haven’t really tried doing client/server replications before, only messed around with NetworkOwnership. So in conclusion, if the moving object will be something controlled and focused (basically owned) by a single player (another example of this would be a car or an airplane), then I would suggest using NetworkOwnership since you want it to be best-optimized for the person. If it is going to be used by many and is not specifically owned by one, then client/server replication is the best. As stated before, I am not the best in server/client replication, so I cannot provide solutions for that, but if you deem as if it would be best to use NetworkOwnership, then I am sure I can provide some input. Hope this helped.
EDIT: Also, another way that you could go about solving this could be using some forces/motors (whatever they are called) in order to avoid CFraming since you already have the hinge and could make a good use of it. Not sure if it will appear laggy to the client. Also, another thing you could do is change the NetworkOwner of the gun only to the client, and let the server handle the movement of the object. That way, the gun turns and responds the quickest on the client, while still being visible to other players. This is another way to approach this problem, and if you do follow that way, I believe you don’t need to update the CFrame on the server. (You would still need to send the shots from the server, but the CFraming will probably not be needed to be done in the server since it’s already done on the client in which the gun is NetworkOwnership’ed to)
Yeah, I just decided to rotate the turret via BodyGryo. I feel like this makes it more simpler and possibility reduces the chances of causing lag.