Casting ray from position a -> position b

Casting ray from position a → position b… Pretty self explanatory, I have been look around the dev forum for the past hour and found no working solution. I have the origin position, and the mouse position where i want to cast the ray to to see what instance it hits if any.

local direction = (b.Position - a.Position)

All about vector maths!

You already have the origin and the target, so all you need is the direction.

Assuming we’re at point A and are looking at point B, our direction will be:

local origin = A --(Vector3 value)
local direction = B - A
workspace:Raycast(origin, direction)

(Im testing stuff, ill mark a response as solution later if it works sorry)

Stuff isnt working and its alot of scripts working together so i cant explain it all too quickly, is there any way to see what the mouse position hits without rays?
Holup i know youre replying, but i just remembered mouse.Target exists, ill try stuff around with that real quick

Well, how’s anyone going to help you without the script? Rays are the best way to do this type of stuff. Dont give up just because it’s hard. Do you think the top devs quit because “MY SCRIPT WONT WORK”?

1 Like

If you get the mouse from player:GetMouse() you can do mouse.Hit for the CFrame or mouse.Target for the part it touched

You can also do to get what the mouse hit

mouse.Target

Hmm i didnt know mouse.instance existed, thank you

Sorry, I forgot what it was called but yes it is mouse.Target

The base of the thing im tryna fix is what i stated so sending a billion lines of other script would seem unnecessary

k well use what I said here instead:

Okay thank you all! abcdefghijkl
Ill mark orbular’s thing as solution since he responded first but thank you all again!