Hello. I’m generating a bunch of puzzle pieces in random locations and rotations like so:
These are all one single mesh not separate actors so I create a FTransform with random translation and rotation and use that to transform the vertices of the piece.
Now when placing these I need to check for overlap of existing pieces in the fastest way possible. Since they are just on a flat table I should only need to check 2d rectangles.
However I’m not sure how to go about this when they are rotated. FBox seems promising because it has “IntersectXY” that will check for intersections between two rectangles but FBox does not include a rotation.
FBox also has “InverseTransformBy” which sounds like it might be helpful however I do not understand transforms well enough to figure out how to use it in this case.
It’s 3d. And checking a rectangle sort of makes no sense at all. pPysics and collision detection have issues with things that have low/no thickness. Even walls/floors/windows. Usually the collision is always a box, never a 4 vertex plane anyway.
If you look up the definitions for what static mesh allows you have box, capsule, sphere, and you have convex.
Unless your puzzle tiles are those of the advanced type (with tabs of irregular shapes) all you really need in terms of points to check is 3 verts per tab (The neck width, and the tab length/apex.)
You can store and compare these values within an array of arrays (cpp) and iterate through the pieces to determine if they are being spawned on top of one another.
Calculating the distance between them on the X or Y axis only and determining if it’s nearly equal to 0.
why are those all the same mesh?
It would be a lot easier to have them be parts of an instanced mesh with a proper system.
It would also allow you to enable complex collision and simulate physics.
As well as the ability to move pieces around and solve the puzzle possibly.
If you are worried on performance, there’s other ways around it. Aggregation/merging is good, don’t get me wrong. (You should probably keep this and then replace the piece with a mesh only when it is interacted with if dealing with puzzles of 1000 plus pieces).
Otherwise, Instances are a better choice.