Raycast Problem

I’m triggering a shooting event using ViewportPointToRay and sending only the direction vector, not the origin, for security reasons. On the server, however, the shot origin is assumed to be the player’s head, which can lead to trajectory misalignment. E.g:

1 Like

Can you explain more about what you are trying to achieve ? ViewportPointToRay returns a ray, which should include both origin and direction. What safety reasons are you not sending the origin ?

Just.. Use a raycast on the camera and get hit.Position and relay that to the server and just have the head raycast face towards the hit.Position point.

@placomi I guess he’s creating a gun or something.

A exploiter can send event:FireServer(enemyHead.Position, Vector3.new(0, 0, 0))

A exploiter can send event:FireServer(enemyHead)

If the origin is changed obviously the entire trajectory will be changed. It is impossible to get the viewport origin from server. What you should do is do the raycast in client and have sanity checks in server, won’t be 100% exploiter free but gives you a balance of security and seamless experience for players.

Nope.

it WILL be 100% exploiter

checks doesnt prove anything ´´´

How do you think FPS games give seamless experience to players? Stubbornness won’t get you anywhere.

1 Like

its impossible to get it 100% exploiter proof unless you want an awful player experience

1 Like

local gun
for _,v in plr.character:GetChildren() do
if v:GetAttribute("Gun) or however you check when they have a gun
reference the part here so

but why would sending the origin matter?? do you mean hit position?

mhm? there will be misalignment if you change the ray origin. you literally cannot avoid that at all. you can’t have your cake and eat it too

you’ll have to think of a work-around, you were given a pretty good one. just do the raycast on the client and check for suspicious activity, or just raycast from the head.
maybe if you could go into detail on what exploits you’re specifically protecting your game against we could help you come up with a better idea

If your concern is aimbot and stuff, you can’t fix that. They can even just use cheats to rotate their camera towards a player and shoot automatically. Cheating is unavoidable (and if avoidable, will become unavoidable soon because humans are smart), you can only really make server sided ways to detect them though.

The best thing to do at that point is measure the shot positions on the body part it hits. If it’s way too accurate on each iteration (like, their shooting an automatic gun that has a pretty good kick to it and it’s hitting right in the same spot, impossibly accurate), then they’re probably cheating and then kick them or disable their HitReg temporarily.

If you’re still wanting to be a schizophrenic about cheaters. You can create some sort of encrypted time based authentication system for your remotes.

UPDATE: I’ve already tried to use (mouse.Hit.Position - head.Position).Unit but it didnt work well on mobile

update: ive solved this problem, i just used another method