Mouse TargetFilter Water?

I want to make a thing turn toward the mouse position. I have everything down except for one thing. How do I target filter terrain water? Is it as simple as I think?

Edit: Is it possible to target filter multiple things too?

I think a better option would be using raycasting, because I believe there’s a way to ignore terrain water by utilizing RaycastParams.

Here’s an example of how that could look:

local RAY_LENGTH = 100

local mouse = game.Players.LocalPlayer:GetMouse()
local rayParams = RaycastParams.new()

--//Set properties of RaycastParams object
rayParams.IgnoreWater = true

--//I'd also assume you'd want to blacklist what the ray cannot hit, such as the player's character?
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}

local function getTargetPart() --//Returns any part the player is hovering on in the game world
local mouseRay = mouse.UnitRay
local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction*RAY_LENGTH, rayParams)

if raycastResult then --//The ray hit something
return raycastResult.Instance
end
end

player:GetMouse().Move:Connect(function()
print(getTargetPart())
end)
2 Likes

Um, I forgot to mention this was a vehicle control system. I also am not very good acquainted with raycasting.

The code I gave you should do exactly the same thing as getting the Target property of the player’s mouse, but it also ignores terrain water cells, which I thought is what you wanted.

I found out that my problem was actually the density of my vehicle, rendering it unable to go underwater. I will problably need to use this in the future for more complicated things. Thank you for trying to help!

1 Like