I’m running into a problem with my A.I character set up where currently I’m having it detect a player via the sight perception stimulus and then focusing on that player with the SetFocus node and having the blackboard key actor being the target as shown here:
It has no issues on server side when checking with the debug tools, but the perception debugger trails behind on the client side. The A.I can still shoot and deal damage to the client player even though it looks like it’s not hitting them. The top video shows the server side and the bottom shows the client side:
I’ve checked that the A.I character BP is replicated and there’s no extra custom movement happening on the player that might cause a delay. I’ve checked the forums and documentation and other resources for a fix and haven’t come across anything. If there’s anything else I can provide to help figure out the problem let me know.
Character class uses CMC which has client-side prediction. This means clients are always ahead of the server with movement. AI is using what the server currently has, then replicating its action down to you.
Clients are 16ms + 50% ping ahead of the server… minimum.
Your view of the servers actions (AI etc) is server tick + 50% ping behind the server.
For AI shooting you want them to lead the shot based on the targets current velocity. Basically where are they going to be next server tick “if” they maintain current forward vector and velocity.
For the visual aspect on clients you can do an Multicast to have the AI sim do a fakey shot at the local clients real current position. Each sim copy of the AI will shoot at the targets current position in each simulation. The servers shot will handle damage and multicasting hit locations for FX.
I hope that I’m understanding what you wanted me to try, if there’s anything else that I need to change let me know.
I think the only thing I’m having a hard time understanding is how the client can be ahead of the server if the server is authoritative even if CMC provides client-side prediction. This is definitely the next big step in figuring out how to really grasp server-client structures so if there’s further resources that best help me understand that I’d love to know what I can look through!
Hey! Sorry for the delay in reply, wasn’t able to get around to this for a bit.
I see what you mean in terms of what is causing the issue with all the delays for the server processing the movement of the clients. The part I’m having trouble with is how to approach managing the delays so that they can all be communicating and synced up properly. Is there anything you can suggest? I’m really stumped on this one.
You’ll never get anything truly synced. Impossible without breaking IRL physics.
Two options to get it close are:
Forward predict player location and shoot there.
Have the sim proxy on all clients shoot at the targets current local position (fake shooting).
Prediction approach is essentially using the same math you would for a line trace. Just use the target location, fwd vector, velocity and the servers tick delta.
I went ahead and recreated your blueprint set up for this. Grabbing the server delta seconds from tick and promoting to a variable to use within the function. It seems to be a little bit better, but I’m guessing that I need to multiply the delta seconds by another value to adjust its speed?
Hey so I think I’m actually fairly close to getting this resolved!
What I’m noticing when playing as client vs server is that the prediction set up is working but only for the server. I’ve set up a debug sphere to help visualize it for myself. Is there an extra step involving a replicated variable or something? You’ll see in the video that on the client on the left side it looks like the AI is caught up with the player movement but on the right the server is getting predicted too far ahead.