Getting direction of a part from raycast

I Tried using lookvectors, but it breaks if the part is rotated differently.

basically i want a part to be somewhat perpendicular as the target, by using raycasts.

im sorry for my lack of drawing skills

you can use raycasthit.Normal (perpendicular to the direction the ray hits)

https://create.roblox.com/docs/workspace/raycasting

Ooo this seems fun!

Here’s how I’d do this.

local raycastResult = -- the ray you just casted using workspace:RayCast duh!

local normal = raycastResult.Normal

local rotationCFrame = CFrame.new(Vector3.zero,normal) -- Vector3.zero is just Vector3.new(0, 0, 0)

redPart.CFrame = CFrame.new(ray.Position) * rotationCFrame

It should be rotated so that the red parts front side is perpendicular to the face your ray hitted.

Hope it helped!! ^w^

i know, but i want it perpendicular to the part, not the raycast. i already tried this method and for my system it doesnt work correctly

What exactly are you trying to do? Can’t you use ray.Instance.CFrame.RightVector?

RaycastResult.Normal does appear to be the normal of the surface hit, not a vector perpendicular to the ray. As this specifies ‘face’, I’m not sure if that means it’s restricted to only Top, Bottom, Left, Right, Front, and Back, or if it would actually give the correct normal for an impact point on, say, a sphere - you’d need to test this.

https://create.roblox.com/docs/workspace/raycasting#hit-detection