Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Parts that should be ignored are interfering with mouse position?

Asked by 6 years ago

In my script I have a part that gets mouse position for a BodyVelocity. When I aim a bullet at a part that has anchored set to true and cancollide set to true, it works fine, same if I aim it at a player. But if I aim it at a part that has anchored set to true and cancollide set to false, then my mouse position screws up and ends up sending my bullet towards a point which is not where my mouse was pointing at. Anyone know how to fix this? I would give code but my code has no errors I can see or fix so I'm really confused as to why it is doing this. All I want the bullet to do is act as if that cancollide false part isn't there and just go through it to wherever I'm pointing.

2 answers

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
6 years ago

There's TargetFilter, which will allow you to ignore an instance and all it's descendants. This will only work when you use mouse.Target to get a target though.

game.Players.LocalPlayer:GetMouse().TargetFilter = Instance

If you simply put everything you want it to ignore in the same model and then set TargetFilter to that model, it will ignore everything inside the model as if it wasnt there (just for the read-out of Mouse.Target)

0
Thanks Wolf5429 15 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Unfortunately CanCollide does not mean the mouse will ignore it, the property is designed to make building easier in some situations. For a helpful solution, assuming there is one, I would need more information on the parts you are trying to ignore, and their vitality to the game, etc.

For now, I can offer two solutions.

Firstly, as Skepticalitys said, you can simply remove the CanCollide parts from your game, removing the option to shoot through parts altogether.

Secondly, you could put a local script inside the gun that temporarily removes the parts from the workspace while aiming at them. With FE enabled this would only remove the parts for the specific client, and everyone else could still see the parts normally. How you were to go about applying this method is up to you, there are multiple options.

0
well I can't do the first option because having this part is vital to the game as it is an attack that is used like an area effect thing. The second option i have no idea how to do that. Wolf5429 15 — 6y
0
could I possibly use TargetFilter? Wolf5429 15 — 6y
0
Nevermind, TargetFilter works like a charm! Wolf5429 15 — 6y

Answer this question