Reflect CFrame based on normal Vector3

I need to make a CFrame which i have reflect depending on the normal vector3 (obtained from a Raycast). The CFrame is equal to

CFrame.lookAt(ray.Position, rayOrigin)

and the normal is obviously just a line which is orthogonal to the ray.Position
theres definitely already a solution for this somewhere, and I have checked (I even tried reading some roblox docs), but I didn’t find anything especially useful.

2 Likes

You can make a CFrame that aligns towards your normal vector through CFrame.lookAlong()

CFrame.lookAlong(yourOriginVector3, ray.Normal)
2 Likes

couldnt you use :Inverse()?

2 Likes

This just gives me a CFrame pointing in the same direction as the Normal (or at least along it). I need it to be on the opposite side of the normal facing the opposite direction.

1 Like

That’s not what :Inverse() does, so it isnt what I’m looking for.

Assuming you’re looking for reflection, you can calculate the opposite normal as such:

-- reflectedNormal code: https://medium.com/@sleitnick/roblox-reflecting-rays-548ae88841d5
local reflectedNormal = (ray.Direction - (2 * ray.Direction:Dot(ray.Normal) * ray.Normal))
local yourNewCFrame = CFrame.lookAlong(yourOriginVector3, reflectedNormal)
1 Like

Yeah this works, requires me to change my code somewhat to get what I want to, but other than that, its good. Thanks! (also, ray.Direction isn’t in ray, I recommend just puttingoriginDirection for future reference if people have the same issue)

1 Like

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