Detect if raycast is against wall or floor

I need to see if the ray is hitting a surface like a wall, and differentiate between the two’s surfaces. I cannot just raycast forward or down because I am making a physics based dodge-rolling system where it raycasts in the direction of their movement, and if it hits a wall, make them bounce back and fall down, or make them finish the roll if the ray gets a floor.

Let me clarify: I need a way of calculating whether the surface a ray hits could be considered a wall or floor.

Name all your wall Parts ‘Wall’ and all your floor Parts ‘Floor’.
If the RaycastResult Name = Wall then do your bounce back or finish the roll if it’s Floor.

1 Like

No I am not going to individually name each part in my games map to differentiate them

It’s good practice but you could use CollectionService and y’know tag all of the parts you need.

And if this is still “too much work” then you can just set ONE material for all of the walls to be made of and then check if the raycast hit that specific material (although if another part has that same material then this won’t work)

Although I would use the first one because it will actually work unlike the second one, I just provided it because.

Just please don’t try to go for the easy methods always. Just a tip from dev to dev

You don’t have to do it individually.
Select all your Wall Parts, then change the name in the Properties window.
Same with the Floor Parts.

1 Like

What i usually do in that situation is using Collision Groups. The workspace:Raycast() has a parameter that allows you to set the RaycastParams, which one of the properties is the CollisionGroup of the ray. So you can set your ray to only colide with your walls.

image

Another approach would be checking the direction of the raycastResult’s normal

The normal’s Y component will be -1 for down and 1 for up, 0 is straight to the sides. So the closer to zero, the straighter is the face hitted, that might be interpretated as a wall.

2 Likes

Checking the direction of the ray normal will probably work in my case Thanks for clarifying and telling me

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