Ray.Unit, what does it mean?

I have never understood what Ray.Unit means, the definition on the wiki says its “The Ray with a normalized direction”.

I have been using Rays a lot lately and knowing this could help expand my knowledge.

Any help is appreciated.

1 Like

It probably converts the Ray’s direction into a unit vector. Didn’t test this tho

Ray.Unit is a normalized vector of the ray’s direction. Normalized vectors have only a length of 1. Which makes sense, let’s take this example:

local point1 = Vector3.new(25, 25, 25) --//Two random positions
local point2 = Vector3.new(50, 50, 50)
local direction = (point1 - point2).Unit
local extended_direction = direction * 50 --//The more we multiply it; the longer the vector will become.
6 Likes

Same issue here, what exactly does it do? How does it normalize a vector of the ray’s direction? I’m a little confused.

A unit vector always has a length of 1. Vector3’s have a Unit property which is a unit vector which represents the normalized version of the vector, and has a length of 1.

Understood it, can it be used on vector3’s only?

Unit is a property of the Vector3 data type, so generally yes.

2 Likes

If you multiply unit vector with, say 24. Will it’s length be 24 as well?

Yeah you will get a new unit vector with length 24

2 Likes

Is it more accurate? If so, is there any article regarding it’s uses? All I know is that it is a property of vector 3 and is a normalized vector.

Not sure what’s it’s exactly use is for…

Unit vectors are needed in linear algebra.

Example uses:

  • Calculating the angle between 2 vectors
  • Linear transformations such as Rotation, Projection, Reflection etc
  • Using the Gram–Schmidt orthonormalisation process to create an orthonormal vector set
  • Calculating the Hesse normal form of a plane
  • Transforming different types of coordinate systems into each other
1 Like