Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a raycast correctly?

Hi guys. Iv tried many things. This is the closest iv gotten. Look at this video I made on my YouTube channel. I recorded how the NPC functions. Just watch to understand.

Video

3 comments

0

Sorry but the recording software distorts my voice, or changes the frequency, btw sub to my channel pls

0

don't ask for youtube subs on scriptinghelpers

0

You have a good question, but you should post your script and the relevant details on the site in text, rather than in a video.

1 answer

✓ Accepted answer

If you read through https://developer.roblox.com/en-us/api-reference/datatype/Ray, the 2nd argument to .new is direction, not targetLocation. You can see an example of how to use it here: https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartOnRay

I would recommend starting at the head of the character and progressing towards the RayDirection.Handle.Position, like this:

	local startPos = script.Parent.Head.Position
	local targetPos = script.Parent.RayDirection.Handle.Position
	local ray = Ray.new(startPos, targetPos - startPos)

This discussion is preserved as it was. New answers, comments, and votes are closed.