Mouse.TargetFilter can only prioritize one instance, how do I get around this?

I made a lock on system for my JoJo game, everything is perfect, but the problem is that the unsummoned stands within the target are blocking my mouse, preventing from locking onto the target. Here’s what it looks like:
https://gyazo.com/d28f3647fbb2a1a3c73904b94ab5f344

Here’s the stand location:

Is there any way to get around this? Or will I have to relocate every stand to be in a specific folder, which will take a REALLY long time to do, this includes recoding everything ;-;

3 Likes

As you can see from the GIF, it did not allow me to lock onto my target because my mouse was over the invisible stand, but as soon as I hovered over the little hand sticking out, it allowed me to.

You can put all the things you want into a folder or a model. As target filter also effects the children of the instance

Yeah, for this scenario don’t use the mouse object when we have the newer superseded version which requires more work to setup but is more customisable for your purpose. Essentially create your own custom Mouse object.

Here’s the steps.

  1. Get Mouse Location on the screen through GetMouseLocation() to get the X,Y coordinates

https://developer.roblox.com/en-us/api-reference/class/UserInputService

  1. Cast a ray from the camera using screen point to ray to a shoot a ray using the previously required x,y coordinates with a direction starting from the camera screen straight forwards (into the page).

https://developer.roblox.com/en-us/api-reference/function/Camera/ScreenPointToRay

Now this time you can ignore instances using RaycastParams which is even stronger as you put an array of Instances which you want to ignore via:

array RaycastParams.FilterDescendantsInstances
An array of objects whose descendants will be used in filtering raycasting candidates.

That’s what I’m saying, like I want it to ignore everyone’s stand not just that one person’s.

Alright, I will try that and see if it works.

Hold on, actually you can just use Ego Mooses UserInputService mouse object instead to save yourself a bit of work, perhaps check it out and see if it works as well?

I already tried his module before, but it doesn’t really apply to my problem and it didn’t solve the problem when I tried to use it, thanks for trying to help though.

I was using your other solution, but I don’t see how I can get the target to lock onto.

local UIS = game:GetService("UserInputService")

local mouse = UIS:GetMouseLocation()

local unitRay = Camera:ScreenPointToRay(mouse.X, mouse.Y)

local ray = Ray.new(unitRay.Origin, unitRay.Direction * 80)

What do I do with this ray?

Well you ray cast it into the workspace to get a raycast result and then you can get the instance the mouse is targeting from that raycast result.

I’m not sure what to put for the raycast parameters, I tried to do this but it said that it was unable to cast double to Vector3

local raycastParams = RaycastParams.new()
raycastParams.IgnoreWater = false
local raycastResult = workspace:Raycast(mouseLocation.X,mouseLocation.Y, raycastParams)

Your parameters are wrong, WorldRoot:Raycast() takes Vector3 first, Vector3 second, and raycast params last

Huh, looks like you can’t get the parent from the ray. I’ll just recode everything, ill still mark as solution for trying to help

Haha, looks like I just needed to dig a little further for help. Here’s the actual solution.

local mouseUnitRay = mouse.UnitRay
local ray = Ray.new(mouseUnitRay.Origin, mouseUnitRay.Direction * 1000)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignoreDescendantsTable)