At its simplest, the cross product of two vectors is a vector perpendicular to those two vectors. The most common application of this is to select two vectors on a plane and use the cross product to get that plane’s normal vector (the vector that points out of the plane, perpendicular to it).
Any situation where you need a normal to 3 points in space, e.g. to build a rotation axis, to work out the angle of impact to a plane (cross gives you normal vector, dot with impact vector for angle), to figure out which side of a plane the player is on.
Sorry, I can’t understand it accurately. Could you give me an simple example? It doesn’t have to be hard; just give me an example related to a game logic. (Just like an object?)
You have 3 balls in space and you would like to spin them round and round in a circle. Pick an arbitrary rotation centre on their plane, make 2 vectors from that point to two of the three balls. Cross those vectors. Apply your rotation to the output.
You don’t know what you need to know until you learn them! And something you learn could be useful in a different project, not always in the current one. It could also improve your way of thinking so you make better decisions in the future.
I really can’t come up with any other use cases other than finding an unknown vector (direction) and finding what angle to rotate an object by.
But I did come across this snipped from a tutorial by EgoMoose
Find this specific snippet in his post
function Placement:CalcCanvas()
local canvasSize = self.CanvasPart.Size
local up = Vector3.new(0, 1, 0)
local back = -Vector3.FromNormalId(self.Surface)
-- if we are using the top or bottom then we treat right as up
local dot = back:Dot(Vector3.new(0, 1, 0))
local axis = (math.abs(dot) == 1) and Vector3.new(-dot, 0, 0) or up
-- rotate around the axis by 90 degrees to get right vector
local right = CFrame.fromAxisAngle(axis, math.pi/2) * back
-- use the cross product to find the final vector
local top = back:Cross(right).unit
-- convert to world space
local cf = self.CanvasPart.CFrame * CFrame.fromMatrix(-back*canvasSize/2, right, top, back)
-- use object space vectors to find the width and height
local size = Vector2.new((canvasSize * right).magnitude, (canvasSize * top).magnitude)
return cf, size
end
Notice how Cross is being used to find the RightVector from just one initial vector so that furniture objects are able to snap to any surface.
So the takeaway from all of this is that you should use Cross for angles and finding unknown vectors simply put. I don’t think I can come up with more ways to elaborate further.