Raycast isnt detecting other parts besides the baseplate

I am making a game where there are aerial attacks, so I used a raycast to see if the player is in the air to do the attack. But for some reason is doesn’t detect other parts other than the baseplate.

Code:

local origin = plr.Character.Torso.Position
local dest = plr.Character.Torso.Position - Vector3.new(0, 10, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {plr.Character:GetChildren()}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(origin, dest, raycastParams)
if ray then
	game.ReplicatedStorage.Events.M1:FireServer(false) --Normal Attack
else
	game.ReplicatedStorage.Events.M1:FireServer(true) --Aerial Attack (In the air)
end

Here a Video showing the problem:
robloxapp-20240519-1358483.wmv (3.3 MB)
(The normal attack is the punch and the aerial attack is the twirl kick)

the aerial attack happens even though I am on a part that is not the baseplate.

Please let me know if there are any problems in the code. Thank you!

Just a small nitpick, but you don’t need :GetChildren() when raycast filtering, as it filters all descendants anyways.

Besides that, try getting a direction instead of using just the destination. The Roblox Documentary has a page about raycasting, and they show you how to calculate the direction. The equation they have is Direction = RayDestination - RayOrigin

1 Like

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