I need help with raycasting

I am very confused on how the directional element of raycasts work. I have created an anti-noclip script with raycasts in the HumanoidRootPart that rubberbands the player if they are in a wall. It works phenomenally at preventing noclipping, but the issue is walking up against a wall causes rubberbanding. How should I be casting these rays?

I am currently casting using

workspace:Raycast(c.HumanoidRootPart.Position,Vector3.new(1,0,1),blacklist)

and

workspace:Raycast(c.HumanoidRootPart.Position,Vector3.new(-1,0,-1),blacklist)
1 Like

the rayDirection is the direction the ray is casted with the length being the number input on the axis it’s casting to (in your case it will be 1) in studs, think of it as poking a 1 stud long part around your character. the problem you’re encountering is that your raycast is touching the wall while the player is not inside it due to the ray being too long, you can try changing the length and see which works best while still keeping it functional

What Vector3 value would you suggest? I’ve been messing with the numbers for around 3 days, and still can’t figure this out.

1 Like

I don’t believe it’d be possible to get it to the perfect length that keeps it functional and short enough to not reach walls while not inside them, this approach would only be able to minimize the effect, I’d recommend trying different methods of preventing noclips if this compromise isn’t ideal

I fixed my issue 100%! It still works phenomenally, and I haven’t gotten a single false-positive! These are the rays:

workspace:Raycast(Vector3.new(c.HumanoidRootPart.Position.X-.7,c.HumanoidRootPart.Position.Y,c.HumanoidRootPart.Position.Z),Vector3.new(1,0,0),blacklist)
workspace:Raycast(Vector3.new(c.HumanoidRootPart.Position.X+.7,c.HumanoidRootPart.Position.Y,c.HumanoidRootPart.Position.Z),Vector3.new(-1,0,0),blacklist)
workspace:Raycast(Vector3.new(c.HumanoidRootPart.Position.X,c.HumanoidRootPart.Position.Y,c.HumanoidRootPart.Position.Z-.7),Vector3.new(0,0,1),blacklist)
workspace:Raycast(Vector3.new(c.HumanoidRootPart.Position.X,c.HumanoidRootPart.Position.Y,c.HumanoidRootPart.Position.Z+.7),Vector3.new(0,0,-1),blacklist)
1 Like