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

How to get the "end position" of a ray?

So, I've made a ray using the following script.

local ray = Ray.new(firePartPos, (target - firePartPos).unit * movementPerFrame)

I've looked through the Ray page on the ROBLOX Wiki, and I don't see a way to find the "end position" of the ray. How would I get that.

(Yes, I know ray's are infinite, but the raycasting tutorial made it sound like the number at the end (movementPerFrame) would restrict the ray's distance. If this does not give an end position of the ray, I'd like to find a way to get the position on the ray with movementPerFrame studs from the starting point of the ray.)

1 answer

✓ Accepted answer

The "end" of a Ray is ray.Origin + ray.Direction.

In general, ray.Origin + distance * ray.Direction.unit is the position that is distance studs along the ray. The end is just ray.Direction.magnitude studs along the ray.

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