The way I’m doing my traces ensures the servers will closely match the clients.
I’m working with true first person, camera is attached to head basically. When I crouch the clients camera stays with the skeletal mesh. If I use a camera reference on the server the cam is in it’s default standing position. So the traces will not match. To get them to you have to use camera manager → get camera location. Same applies for rotation and forward. Can’t simply use the cameras rotation, you use control rotation or base aim rotation. Base Aim Rotation is the better option, it’s more accurate.
For shooting I have two setups. One for hip and one for ADS. The Hip shooting does a line trace forward and I take the impact if a hit occurred, else trace end, then find look at rotation from muzzle to the that location. This gives me an Aim vector to use for my projectiles Aim velocity.
For ADS firing you don’t have to trace. (Muzzle location + (Cam Forward vector * n distance)) will give you a aim point. Multiply that by muzzle velocity and you have a Aim Velocity Vector for the projectile.
Shooting logic on my end is split into Proxy based systems. Client (Autonomous), Server (Authority) and then Simulated to get your shots on other screens.
My projectiles are object pooled. So no "spawn/destroy perf hits.
Client fires a local only projectile that interacts with the world. Impact fx such as squibs and decals etc. Client then sends an RPC to the server to fire. Server fires its own local projectile. Then Multicasts to Sims to fire their local. Server passes the relevant info to sims (aim velocity etc).
When the server hits it multicasts the Hit location/normal etc to SIMS. If a player is hit it RPC’s the hit player with custom hit info.
No projectiles are replicated in this setup. It’s all low data localized.
Here’s a demo of it. Mind that I haven’t finished setting up left hand IK or Aim offset. Weapon in the demo is simply attached to the right hand.
Also should note there are 3 projectile classes (autonomous, simulated and authority) as well as dedicated obj pool managers for each. Each projectile class is coded to do its specific job. No carry over bloat.
e.g. clients have a visual element, sims/server only collision. sims has audio flyby (whizz). server has hit reg → dmg etc.