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 vector3 from ray with magnitude?

I am trying to get a position (Vector3) from a ray (or whatever, i have origin and direction) With a specific distance or magnitude.

for example:

ray = Ray.new (origin, direction)
-- this is a imaginary scenario vector3 = ray:GetVector3FromMagnitude(5) -- 5 studs

this should give the vector3 at 5 studs from the origin of the ray in the direccion of the ray, Ignoring any hit, player, terrain, etc.

it's does not have to be a ray, it's does not have to 5 studs. Any help would be appreciated

1 answer

✓ Accepted answer

Direction Vectors

If you only want the direction of the ray, then it is a property of the ray itself.

local ray = Ray.new(origin, direction)

local directionVector = ray.Direction
local unitDirectorVector = directionVector.Unit

Position Vectors

If you want the position of the point x units from the origin in the direction of the ray, then you have to use the direction vector to "move along" the ray.

local ray = Ray.new(origin, direction)

local directionVector = ray.Direction
local unitDirectorVector = directionVector.Unit

-- Where x is the distance along the ray.
local positionVector = ray.Origin + (unitDirectionVector * x)

1 comment

0

Work good, thanks

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