Hitscan gun system has trouble with moving targets

In the video below, sorry for the bad quality, I am shooting an example target dummy to test out the different types of my hitscan guns, however it really struggles with moving targets. It creates a raycast and detects any hits, however, I don’t know whether its delay or something is wrong with the script, but it really has a hard time with moving targets. I tested this out with some friends to play it out erlier, and it was really hard to shoot them. Any solutions, I can provide code if needed.
Any help is appreciated.

Video:

1 Like

we need source code or atleast the method you used, with no info i cant help

Hello! The reason for this is due to server client latency.

  1. when you fire remote event of the mouse position from server to client, there is a latency which is around 100ms
    2)On the player’s screen the moving rig is around 2-6 studs behind the position the server thinks the rig is

Ok so now you know the problem, how to fix it?

  1. use client side hit detection
    client side hit detection is the best solution for hit scan weapons like gun,sword , ect as you can just send the raycast results to the server using remote event. for sanity check:
    1)check the said origin by the client with the server origin position eg) if (clientOrigin-ServerOrigin).Magnitude < 10 then print("pass") end
    2)raycast from client origin to client destination. in raycastprams , make sure to set both atttacker and victims character as blacklist . If there is nothing blocking. you can be quiet sure that the shot is vaid

KEEP IN MIND
Server side hit detection make ot harder for hackers to hack. however , it is very unreliable

5 Likes