I am working on making a SCP-173 AI, essentially when you aren’t looking at him he moves and tries to get close enough to kill you (I would suggest reading the wiki or looking at footage of the game for more details) I want to handle checking if the player is looking at the SCP on the client, as it is much faster and I want his movement to be as seamless as possible, I am just confused on how I should approach this. I thought about using remote events but I don’t know how I would link pathfinding to that, I would prefer to use a bool value or something instead, but is that even possible? Here is localscript I am using for detecting if a player is looking:
local RunService = game:GetService("RunService")
local scp = workspace["SCP-173"]
local char = script.Parent
local plr = game.Players.LocalPlayer
local plrgui = plr:WaitForChild("PlayerGui")
RunService.RenderStepped:Connect(function()
local Chartoscp = (scp.Head.Position - char.Head.Position).Unit
local CharLook = char.Head.CFrame.LookVector
local DotProduct = Chartoscp:Dot(CharLook)
if DotProduct > .5 then
print("Looking at scp")
plrgui.eye.Blink.Status.Text = "Status: Looking at scp"
else
print("Not looking at scp")
plrgui.eye.Blink.Status.Text = "Status: Not looking at scp"
end
end)
This script works very well and is almost instantaneous, but is there maybe a just as fast way to handle this on the server? I’m honestly not sure about all of this. I want the client to tell the server when the player is or is not looking, then either pathfind to the player or don’t move at all on the server essentially.
This statement raises problems when it comes to exploits. You shouldn’t rely on the client to provide this information, and even if you do you would need to sanity check it either way.
No matter what you do there is going to be some kind of disconnect, unless you move a spoof “SCP” on each client (and provide NetworkOwnership) rather than doing it on the server. You would then sanity check any kind of damage or ultimate ending result on the server before enforcing it.
Client’s have NetworkOwnership over their character, which means the physics of the character are being simulated by a different owner.
I’m not sure how much sense this will make under context of this post, but this thread does a decent job explaining how some larger games (ex. Rocket League) simulate physics so that everything is seamless but the server is still authoritative.
'what is typically done on the client is to correct back to the “authoritative state” via rewinding of the localized simulation, re-injecting inputs, and then fast forwarding to the corrected state, and then, interpolating from the existing client state to the corrected state, over a small number of timesteps, so that the client doesn’t exhibit “warping”
This is difficult to accomplish on Roblox but not impossible, it would just be implemented differently.
Ultimately I think hyper-focusing on this system before completing the rest of the game is a certain waste of time. Better to mess with this type of performance at the end because it will barely impact other systems that you have wrote.
This is intended to be a single player game so exploits aren’t really of a concern to me, I just don’t know of a way fast enough on the server that would prevent you from seeing it move, that’s why I want to do it on the client. If the player is able to see the SCP move because of delay between the server and client it could hurt atmosphere considerably, but I appreciate your response.
Since it is single-player and exploits are not a concern, could you give the player NetworkOwnership of the SCP so that the physics are simulated alongside of the character. You could still do your final checks on the server, but when exploits aren’t a concern (I think they should be even in single-player games) you have a lot more freedom to entrust the client with physics simulation stuff.
You could also alter the width of the accepted dot product result to allow for a safer margin of error within the disconnect.
Unfortunately I did not realize that SetNetworkOwner is only for unanchored parts with physics, I am looking for either instant CFrame movement or tweening movement, I should have been more clear in my original post.
Then I would say alter the width of the accepted dot product angle to allow for a greater error margin. You shouldn’t need much in a single player game.
Also, you don’t need to directly use SetNetworkOwner, you could also just create the SCP on the client itself and it will be simulated alongside of the character. If you still planned to trust the server with sanity stuff then you could track the ideal SCP position on the server and finalize your checks with that.
Honestly though I think you’re overexaggerating how big of an issue this will turn out to be, the disconnect that exists is barely a fraction of a second so with a larger angle you would likely see no issue on clients with reasonable latency.
You can tween and assign CFrame values to CFrame properties from the client through local scripts, it’ll only replicate for the local player but it will essentially enact in real-time (time of execution similar to that of observation).