I’m trying to raycast towards a certain object, but I’m not sure how to make the ray face the part.
so ray’s components are Origin and direction and for direction u can use: part1.Position - part2.Position
also mind that the order does not matter
Roblox made an article about raycasting, which shows you how to find origin, direction and destination.
You can use Cframe.lookAt to aim at the part, and then fire the ray
You can calculate the direction vector by subtracting your target part’s position with your origin vector and then dividing this new vector by its magnitude to get the unit vector - which is a normalized directional vector with the length (magnitude) of 1.
I mean if you do (b.Position - a.Position).Unit won’t it just return a normalized Vector of the result of what’s in the parenthesis instead of dividing the new Vector by it’s magnitude since Math Operations in parenthesis return the result before doing anything outside of the parenthesis?
Yeah you can use .Unit, it’s essentially the same thing.
When you perform an operation on vectors like this in parentheses, then it’s just because you’re wanting the .Unit or .Magnitude of the new vector product, since instead it’d turn out like this if you weren’t using parentheses: b.Position - a.Position.Unit which would result in subtracting b.Position with a.Position's normalized vector which would result in a completely different thing.