The dot product of two vectors A, and B given A:Dot(B) is the same as:
A.Magnitude * B.Magnitude * Cos( Theta )
Where Theta is the angle between the vectors A and B. This is very useful when used with knowledge of trig, or to get the angle between vectors. The case study in the Dot example is one use, another frequent use of the Dot product is to quickly get the angle between two vectors by doing:
math.acos(A:Dot(B) / (A.Magnitude * B.Magnitude))
Or using unit vectors (Vectors with a magnitude of 1) then the division is not necessary.
The Cross product of two Vectors will give you a new Vector which is perpendicular to both. i.e if you have two vectors Vector3.new(1,0,0) and Vector3.new(0,0,1) then the Cross product will give you ± Vector3.new(0,1,0)
An example use would be; to get the surface normal of a Triangle.
Case study: Rotating a turret to face in a direction, with a maximum turn rate
local GoalDirection = Vector3.new(1,1,0)
local TurretCFrame = CFrame.new(Vector3.new(), Vector3.new(-1,0,1))
local TurnRateDegrees = 10 --Max turn rate 10 degrees per second
local LastBeat = tick()
game:GetService("RunService").Heartbeat:Connect(function()
local dT = tick() - LastBeat
--Distance = Speed * Time, Speed = TurnRateDegrees, Time = dT
local StepTurnMax = TurnRateDegrees * dT
local CurrentDirection = TurretCFrame.LookVector
--Get the angle in radians between current direction and goal direction
--unit vector magnitude is 1, therefore no division needed
--Convert to degrees to match our StepTurnMax
local TurnAngle = math.deg( math.acos(CurrentDirection.unit:Dot(GoalDirection.unit)) )
print(TurnAngle)
local TurnAxis = CurrentDirection:Cross(GoalDirection)
--Limit the angle of turning to the maximum for the beat
local TurnAmount = math.clamp(TurnAngle, -StepTurnMax, StepTurnMax)
--Rotate the Turret CFrame to make it face by the Turn amount
--It'll rotate about the cross product of the two vectors, imagine a
--pin through the crossproduct, that it turns about / hinges about
--convert back to radians for the CFrame rotation
TurretCFrame = CFrame.fromAxisAngle(TurnAxis,math.rad(TurnAmount)) * TurretCFrame
LastBeat = tick()
end)
If you were to run this in studio, you would see the angle difference would decrease by 10 degrees per second, so it’d take 12 seconds for the turret to rotate to face it’s target direction (which was 120 angle diff between the two)
EgoMoose’s articles are extremely detailed, certainly more so than my answer so I don’t really know how to help you beyond an example use for both.