Let’s drop into 2D and plot out an example.

Here, the Gun is positioned at (0, 10) while the Mouse’s Hit is positioned at (10, 15).

When we subtract the the Mouse’s Hit position by the Gun’s position, we get the vector [10, 5]. This is known as the ‘displacement’. Fundamentally this is a useful value as:

(Position[1] + Displacement) = Position[2]

(Position[2] - Displacement) = Position[1]

And when we feed this displacement into Raycast, it’s actually representing both a ‘Mangitude’ and a ‘Direction’.

Direction is the easy part. If our displacement is [10, 5] then that can be interpreted as that in order to go from the Gun’s position to the Mouse’s Hit position, we’d travel 10 Units forwards, and 5 Units up.

Magnitude is actually the length of that line (the length of the raycast).

Which in our case is roughly 11.18

When we take the Unit of a vector, what we’re doing is we’re dividing that vector by its magnitude. By doing this, we’re creating a new vector that only has a magnitude of 1, but is still representative of the former vector’s direction. For us, this works out to be about [0.894, 0.447].

And this normalized vector (this Unit Vector) turns out to be very useful as it allows us to assign a new Magnitude through multiplication. In your example, the Unit Vector was multiplied by 300, which is to result in a Magnitude of 300 studs. Meaning the Ray will start from the Gun, and continue for 300 studs in the direction toward the Mouse’s Hit. If we were to apply that to our example, the ray would actually extend waaay past the Mouse’s Hit position, ending at about (268.328, 134.164).

Knowing this, the math in your example is actually undesirable. Unlike as corrected in my example, it actually subtracts the Initial Position (the Origin Position) from the Final Position, rather than the other way around. This would actually result in the ray traveling the complete opposite direction! Moving away from the Mouse’s Hit Position rather than towards it.

(10, 15) - (0, 10) = (10, 5)

(0, 10) - (10, 15) = (-10, -5)