How to make a raycast not stop at a part on the same angle

I am making a raycast for a rope but sometimes the ray picks up parts directly under it even though they have the same surface angle.

What I mean is that if I made a ray start at the gray part where my mouse is hitting, it would stop at the red part. If you don’t understand still:

image
The ray would end at the purple part because I’m raycasting straight down from the mouse hit position. How would I avoid it detecting parts that are directly under it like the red part to the gray part?

ULTIMATELY it ends up making the rope very short if a part is under the part where the mouse is

If you need code ask me.

1 Like

Parts have a property called “CanQuery”, try turning that off. Basically BaseParts that have CanQuery turned off are ignored by Raycast checks

You can also set up a parameter for your Raycast and add the purple part into its blacklist which will also make your Raycast ignore the purple part.

I see but the player can place the rope anywhere, which means I can’t turn off CanQuery for every part. I want it to ignore the part if the surface angle between the two is 180 degrees if you know what I mean.

1 Like

Ok I read over your initial question so let me know if I’m still not understanding it correctly.

Basically what you’re trying to achieve is create a rope that reaches all the way down to the nearest ground from the point you clicked with your mouse, but because the raycast starting position is too close to the wall it detects anything under that initial part even though they are completely aligned?

In that case I would add a slight offset that goes the opposite direction of your mouse click such that the target position isn’t right up against the wall.

1 Like

I just want to add that ideally you’d probably want the rope to offset in the opposite direction of the target face you clicked on. This might be slightly farfetched but you could run two separate Raycasts to do this since there is a property called “Normals” that RaycastResult returns

This is basically a direction vector which you could use to offset the rope slightly in the direction that the face you clicked on is looking at (this works with custom meshes too I believe), then cast the second Raycast downward from this new position to get the length you need for the rope

1 Like

Ok, thanks. Let me give it a go and I will tell you how it goes.

1 Like

Absolute lifesaver. It might’ve took longer than it should’ve but more work, more reward! Thank you very much.

1 Like

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