RespectCanCollide Rays hitting arms and legs of R6 characters

Hello, I’m currently making a gun script, utilizing workspace:Raycast(), and for obvious reasons, I have RespectCanCollide set to true. However, this makes it so Players can’t be hit in the arms or legs, as the arms and legs of R6 rigs don’t have collisions.
Of course, I’m sure I can find workarounds to this, what I did when I was using workspace:FindPartOnRayWithIgnoreList with an older system serveral years ago is make an ignore list with every BasePart descendant of workspace other than arms and legs with CanCollide set to false. However, this is obviously not the most efficient method, so I’m wondering if there’s a better way?
Thank you in advance.

1 Like

Are you using a RaycastParams object? You could use one containing all of the parts in every target’s character in the FilterDescendantsInstances and set the filter type to Include. Then, you might not need RespectCanCollide.

1 Like

RespectCanCollide isn’t what you want to be using. RespectCanCollide’s documentation states that it makes raycasts utilize CanCollide instead of CanQuery when determining whether or not a part is relevant to the raycast.

You may be making the incorrect assumption that if it isn’t enabled, raycasts will fly through walls and everything collidable because it doesn’t “respect” the fact that they’re collidable.

RespectCanCollide instead fundamentally alters how raycasts behave by both:

  • targeting collidable-yet-so-called-unqueriable parts and
  • not targeting uncollidable-yet-so-called-queriable parts (like legs and arms)

In the case of legs/arms, it’ll neglect to target them because they aren’t collidable. You should have RespectCanCollide set to false so the raycast can hit them along with every other part.

If you have uncollidable parts you don’t want impeding bullets, disable the part’s CanQuery property or modify collision group behavior between the bullet and the part.

2 Likes

I didn’t even realize that was a property of parts. Shows how long it’s been since I’ve done this stuff. Thanks!

1 Like

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