New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

Can someone explain the Vector3:Dot(Vector3) function to me?

Asked by
Psudar 753 Moderation Voter
5 months ago
Edited 5 months ago

I'm trying to learn a bit of math here so bare with me, but let's say we have this program:

local vector =, 2, 2)
local vector2 =, 2, 2)


--//Dot equation: P * Q  =  Px * Qx + Py * Qy + Pz * Qz

local Px, Py, Pz = 2, 2, 2
local Qx, Qy, Qz = 2, 2, 2

print((Px * Qx)+(Py * Qy)+(Pz * Qz))

Output: 12 ; Output: 12

I'm tying to figure out what the Dot function actually returns, but I dont really understand what the number means. I understand the equation just fine, I just dont know where to use this.

If someone could give me a use case and a bit more in-depth explanation, that'd be awesome.

1 answer

Log in to vote
Answered by 5 months ago

Dot product is a scalar unit, not a vector unit, meaning it has no direction.

Dot product of two vectors are calculated by multiplying both vectors length/magnitude and then multiplying with cosine of the angle between the vectors:

One application is detecting orthogonality/perpendicularity of vectors if the dot product is zero. If vectors are perpendicular(angle between them is 90 or 180) then dot product is zero, so you know that they are perpendicular.

If you divide the dot product by the lengths of the vectors, you're left with the cosine of the angle between the vectors, so the arc cosine of this will be the angle.

How do you find the angle's cosine between the vectors? Psudar 753 — 5mo
Based on formula of Dot product Cosine becomes result of the Dot Product divided by product of both vector lengths multiplication. In formula Cos(?) = (aVector · bVector)/ (aVectorLength * bVectorLength) GooierApollo664 163 — 5mo

Answer this question