NPC not catching up with player

Hi

I’ve made an NPC that chases you, its speed is 10 studs faster than the player (100 studs) but when you and the NPC are at max speed, it always seems to be really far behind. I’ve checked out other speed-based horror games but they don’t have the same problem.

All i could suggest is lowering the walkspeed in the humanoid.

Assuming the NPC code runs on the server, the NPC lags because the server position of the player is behind the client position. At such high speeds (as in your case), the desync in position could be massive (like your case).

  1. This is an annoying problem for multiplayer and the solution I had was to make the NPC go to where the player is going to be instead of where he’s at.

  2. Singleplayer has an easy fix, make the NPC’s code run in a LocalScript so there’s no desync.

    • This solution can work in multiplayer, but desync could become a problem if not handled correctly.

Ah alright, that makes sense. But how would I make it so that it knows where the player is going to be? Is that like a ray or something? Since I am planning to make this a multiplayer game.

I just take the player’s current position then add their velocity to get where they’ll be.

Equation should look something like this.

local multiplier = 1
local predictedPosition = (playerPosition + playerVelocity) * multiplier

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.