Devlog 3








Turret setup/controls
After I completed and tested the car movement system, the next major gameplay mechanic I did was the turret controller. Our core idea was to have one player drive each vehicle and another play a turret mounted on the roof. In order to implement this mechanic, I downloaded a 3D turret model from the Unity Asset Store and attached it to our vehicle prefab.
I then coded a custom script to control turret rotation. The design goal was to get the turret to respond, feel smooth, and be fun to move around, yet also have it integrate into our role-based multiplayer framework.
To have control over the turret with full precision, I split the turret prefab into separate components—like cannon base and cannon head—through a parent-child structure. I could then rotate the base left-right and the head top-bottom independently. This type of setup gave me proper control over aiming, smoother rotation, and improved clamping vertical angles without interfering with the base rotation. It also kept the system modular, thus it was easier to substitute components or animate them separately in the future.
The TurretController script handles turret rotation and shoot behaviour for the turret on top of the car. It receives input from the assigned shooter player, rotates the turret horizontally (base) and vertically (head), and duplicates those across the network using NetworkVariables. Rotation input is reported back to the server via ServerRPCs, which update shared values for all. The script also has a FireServerRpc() method that uses raycasting to track hits and do damage via the IDamageable interface. Shooting mechanics will be explained in the upcoming devlogs.
To ensure that only the shooter shoots, it checks to see if the local client is the assigned shooter before accepting any input. This ensures that only the correct player can use the turret, thus eliminating problems of conflicting inputs in multiplayer and ensuring proper role-based gameplay.
Mouse movement input for horizontal and vertical translation is read on the client of the shooter. These are the amounts of how much the player wants to turn the turret head and base. Instead of applying them directly, they are sent to the server to maintain network authority.
The server receives the mouse input deltas via a ServerRPC, calculates new yaw and pitch, clamps them within reasonable limits, and sets two NetworkVariables. This makes all turret movement authoritative and cheat-free.
In LateUpdate(), the turret head and base are rotated according to the networked values at the current moment. This ensures all clients see smooth and consistent turret movement, and visuals stay perfectly in sync with the shooter's actions.