How To Make Wall Slam Blocks Get The Color And Material Of The Wall They Are Attached To?

Continuing the discussion from How To Make A Wall Slam Effect After Ray Hits The Wall, this is the final one:

The white block is the place where ray hit, but as you can see, the blocks of the wall slam effect are planks even on the side of grass, so I want to make blocks get the material and color of the place where they are located, I guess raycasting is a solution here:

local ray = workspace:Raycast(Rock.CFrame.p,???,rayParameters)

I’ve tried to write (Rock.CFrame * CFrame.new(0,0,-5)).p, but it didn’t work sadly.

The orientation of rocks is random, so I think CFrame.lookVector doesn’t work here, so I need an alternative.
Can you help me find out what should I write instead of “???”, so the rocks will get their material, also make it so it will work on any direction the ray hit? ( I mean it will work no matter what direction the origin of the first ray was facing: Left, Right, Forward, Back)

Could you not cast a ray at the reverse normal of the original ray on each of the parts as to figure out what material theyd be? It’d look something like such:

-- Whatever loop you have, creating the part, etc
local partRay = workspace:Raycast(part.Position, -originalRay.Normal * 5)
if partRay then
   part.Material = partRay.Instance.Material
   part.Color = partRay.Instance.Color
end

Thank you for the response, for some reason, this doesn’t work, none of the rocks got it’s material.
You can check all the code in the previous topic to test it by yourself, but I think that all we need is guess the right vector from the block. Maybe Vector3.fromAxis() can help here?

Maybe GetTouchingParts() and checking for parts that are not part of the explosion pieces?
https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts

Your best shot is to cast rays from the crater parts before changing color and material, facing the same direction as the slam occurs(the normal). After the raycast, change the color and material to the corresponding part hit by the ray.

Yeah, that’s what I was thinking about too, the problem is I don’t really know what direction I should make.

And what if there are two parts (two walls) hitting the block? Like in the screenshot I made at the beginning?

You could use Magnitude to determine which is closer.

Alright, I’ll try to do it your way, but I’ve found that if I use Vector3.FromNormalId(Enum.NormalId.Front)*-5, it will work partially, so maybe we can test some of Vector3 constructors?