Is it possible to detected another player character behind player character with Raycast?

So yeah right now, I’m having an issue/trouble about the detected player character behind another player character in Server Script But I don’t know how to do it, I just went searching through all the devforum threads but all ended up client-side.

Why do you want to detect from the Server Side?
The reason I don’t want it to be client-side is that to be safe for myself, I don’t want the script getting decompiled by a handy software user.

An Image, If you don’t understand.


ALTERNATIVE LINK (in case the video can’t watch): https://streamable.com/ebsftr

If you don’t understand, I’m really sorry because my grammar is very poor, I hope you understand what I mean. Thank you!

(If you could give me a sample that would be great!)

1 Like

Sorry but I don’t understand too well.

Do you want to do something like this?

Or is the ray supposed to come from another part like in your original picture?

1 Like

Could you show us your script so we can see what you’re doing wrong?

Hello, are you sure you want to use Raycast to detect it?
There’re plenty another ways to do it.

Use the dot product instead.

Here’s an example how it works:
Math for Game Developers - Backstabbing (Dot Product) - YouTube

It’s mot efficient way to do due it costs less memory for calculations.

1 Like

If I understand what you’re trying to do, you should add all player’s characters to a blacklist in the raycast params to just ignore them when you cast the ray.

No? All I need is a ray through player 1 so player 2 can receive an action as player 1 received
image

If you put all the players’ characters on the blacklist, The ray from the source part will not hit the character Because player’s Character is Blacklisted.

You would blacklist every character other than the local character. If that’s a problem then you can just cast another ray in the same direction originating from the first ray’s hit if you detect that ray hit a character to see if any other players are behind the one player.

Maybe do a small loop where it casts a ray and if it hits a character (finds a humanoid in what it just hit) then store the character and cast a second ray with that character blacklisted in filtering. And then repeat that loop until no character is hit.

Something like this:

local RaycastFinished = false
repeat
	if Character:FindFirstChild("HumanoidRootPart") then
		local OtherCharacters = {}
		local rayOrigin = Character.HumanoidRootPart.Position
		local rayDirection = game.Workspace.Part.CFrame.LookVector

		-- Build a "RaycastParams" object and cast the ray
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {Character, OtherCharacters}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

		if raycastResult then
			local hitPart = raycastResult.Instance
			if hitPart.Parent:FindFirstChild("Humanoid") then --Found a "Humanoid"
				if hitPart.Parent.Humanoid:IsA("Humanoid") then --Verifies that it is a real Humanoid instance
					--Insert it into table
				else
					RaycastFinished = true
				end
			else
				RaycastFinished = true
			end
		end
	else
		RaycastFinished = true
	end
	wait()
until RaycastFinished == true

Not sure if this actually works. Hopefully you get what I’m saying though.

Sorry if the script is confusing I just quickly put it together.

3 Likes

I think that it put the effort too much, This is my reference one

The code looks interesting to me, I hope this might help, Wait its morning, I’ll try to learn from your source! and adapt it to my source :smile:

1 Like

As what @drewbluewasabi said, you need to make recursive raycast, by checking whether hit part is a descendant of player character. If criteria is met, store and add them to ignore list, and re-cast ray until hit part is solid or is a descendant of local player character.

2 Likes