Help with debugging raycast's direction

    local MyParams1 = -- ray 1 parameters
    MyParams1.FilterDescendantsInstances = {ObjectsToIgnore, char}
    MyParams1.FilterType = Enum.RaycastFilterType.Blacklist
    local BulletResult1 = workspace:Raycast(Origin, Direction.Unit * 500, MyParams1)
    if BulletResult1 and BulletResult1.Instance then -- if ray 1 hit a wall (basically if your bullet hit a wall, then)
        local MyParams2 = -- Ray #2 parameters
        MyParams2.FilterDescendantsInstances = {ObjectsToIgnore, char, BulletResult1.Instance} -- make the 2nd ray ignore wall which the bullet is shot at
        MyParams2.FilterType = Enum.RaycastFilterType.Blacklist
        local BulletResult2 = workspace:Raycast(Origin, Direction.Unit * 500, MyParams2) -- cast out 2nd ray
        if BulletResult2 and BulletResult2.Instance then -- if 2nd ray hits something, then
           -- stuff

This is a simplified version of my script. It shoots out a first ray, then shoots out a 2nd ray which ignores whatever the first ray hit. The first ray works just fine, but the 2nd ray seems to point slightly downwards. The closer the first ray is towards the wall, the more the 2nd ray points downwards

The direction is the exact same and was never changed between the 2 rays

Just found the issue, but I have no idea how to fix it
The ray goes from the player’s head to their mouse’s 3D position
The issue is that the head is above the player’s camera. If I were to cast a ray from the camera to the mouse’s 3D position, hackers could exploit this to kill people through walls

Any ideas are appreciated

Cast the ray from the gun barrel to the cursor position, not the head.

The gun is only displayed on the client, and the raycasting is done on the server
If I were to pass the position of the gun’s barrel to the server, exploiters could also use that to kill other players through walls

Can you offset the Position of the raycast from the head Position lower and right to match up closely with where the gun barrel is?

That’s a good idea, I can give that a try and let you know how it works
Unrelated note, I’ve played your boat obby game many years ago. Nice to recognize someone from so long ago lol

1 Like

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