When doing a directional vector, which is what you’re doing, for example, in this raycast, you should always offset it from the target to the start, and not the start to the target.
Vector a - Vector b = Vector c
Vector a + Vector c = Vector b
Take, for example, a 2D cartesian graph.
This is what you currently have:
You’d want to get this:
However, by subtracting the origin vector to the destination vector instead of the opposite, you invert their pointing (it’s inverted), making it go from the destination point to the origin instead.
By swapping the order it should fix your problem: (Destiny.Position - script.Parent.Position)
By the way, try using lua code blocks. You make them by starting one line with ``` and ending another with the same characters.
Pretty sure I mentioned this. Sorry if it wasn’t clear enough.
In his specific case, he is subtracting the origin position vector to the target position vector.
This creates a vector pointing from the target to the origin, based on how vector subtraction works overall.
He should avoid this, as the ray created would be pointing in a different way than the one he’d like it to.
Therefore, he should always subtract the target position vector to the origin position vector, and not the other way around. This creates a vector pointing from the start to the target.
This can also be seen with the Triangle Law of Vectors.
The position vectors go from the origin to their coordinates. Their subtraction “links” the two coordinates together, resulting in a vector that goes from one to the other, instead of the origin of the graph.
I’m not sure you’re comprehending my post correctly. The directional vector you’re calculating is and should be from the start to the target. Note that by this I mean from the start or origin of the ray – not the world – to the target. I’m not referencing the order of subtraction, which is where your misconception seems to stem from.
Saying you should always offset it from the target to the start, and not the start to the target is incorrect, since a - b gives you what to add to b to get you a.
For a vector (1,2,3), it’s unit directional vector from the origin is ((1,2,3) - (0,0,0)).Unit. It’s directional vector from a point (1,2,2) will be (1,2,3) - (1,2,2) = (0,0,2).
Hence the directional vector v3 = v2 - v1 is from v1 to v2.
Ah, yes, this is true, however I was referencing the specific use case on ray casting where the origin is already defined and you’re casting from the origin to somewhere else.
Apologies if I made it seem as directional vectors are from the target to the origin and not the opposite, I was trying to explain why in the ray it’s intended to do the (Target - Origin) instead of (Origin - Target), but I guess I might have explained it poorly.