Get how much a ray was multiplied by to get the result position

Hey developers so I was working on something where if you clicked it would send out a ray with a direction multiplied by 25.
What I want to know is how much the ray direction was multiplied by to get the result position. This is probably really easy but it’s stumped me for hours now.
Thanks for any help :slight_smile:

1 Like

Maybe some more explanation on your part would help… If I understand, you have some sort of Vector3 (..., ..., ...) and are multiplying it by 25 (the max distance). Then you are feeding it into a raycast. You would like to know how far the ray went before hitting something.

In that case, you would want to use the RaycastResult.Distance property.
(RaycastResult | Documentation - Roblox Creator Hub)

Example code:

...

-- Raycast code here
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)

local distance = raycastResult.Distance

It’s really simple, honestly. I suggest you read up on the documentation, it should explain a lot of questions you may have.

Let me know if this is what you are looking for! Good luck :slight_smile:

3 Likes

I figured that bit out about 10 minutes ago lol. But what I need is to figure out how much it was multiplied by so like 10.9 or 1.875 however whenever I think I have the right value I try multiplying them and it give me a completely wrong value

Testing

Edit: This is how I doing it:

1 Like

You really don’t need to do all the complicated stuff that you are doing. Just do raycastResult.Distance. Anyway, glad you got it figured out! If I helped at all, I would appreciate a marked as solution

2 Likes

I need to get how much it is multiplied by so that then I can add in an extra distance and make sure it is within max distance on the server

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.