How do you get the end position of a ray that hasn't hit any parts?

This is a pretty solid question, and the title basically explains itself. Does anyone know how to make a part position when aiming a ray in the sky or some area without any parts?

2 Likes

Logically, if the ray doesn’t hit anything, the end position is origin + direction.

4 Likes

What about getting the size of the ray and the position between like start, end?

local result = workspace:Raycast(origin, direction[, params]) -- cast ray
local intersection = result and result.Position origin + direction -- get intersection
local in_between = origin:Lerp(intersection, 0.5) -- get in the middle
local length = (intersection - origin).Magnitude -- get length
2 Likes

How does workspace:Raycast work? You typed ‘[, params])’ which is kind of confusing. Also like how do you get the intersection because I see you typed result and result.Position ’ origin + direction’ and that part doesn’t work at all.

It was meant to be pseudocode, so not something you can directly paste into your project.

Have a look at the intro to raycasting article:

Yeah, I don’t know what pseudocode is also how am I supposed to know how it works when you add in errors like [, origin], and ‘Position origin + direction’? You can’t even add 2 parameters to [this, this] that doesn’t even work.

I looked up how to use the worldroot:RayCast(), but it doesnt specify what you did at all.

1 Like

Would recommend how to raycast before trying to learn how to find end positions, lengths, etc…