Calculate normal between two vectors

Hi, i need to add an instanced mesh to one actor (A) based on location of another actor (B) without traces or something like that because i have a collision component attached to B actor .


What i know is only location of A and B.
In the above picture B is on the right of A, this mean the normal == A.GetActorRightVector
B can stay at every side of A, so to spawn another mesh i should know wich side, so by getting normal.

Can someone help me? Thanks

B.GetWorldLocation - A.GetWorldLocation then normalize the resulting vector.

That gives you the normal of B compared to A… is that what you meant?

Exactly thank you TK-Master, i didnt know that normalize do that :rolleyes: However now i need to snap B on front/right/back/left of A.

I’m trying to do it with SnapToGrid(float) but maybe there is some better ways?

Any help please?

Assuming you’re using cubes, SnapToGrid should work. Just break that vector, SnapToGrid each element, make it back into a vector, and that’s your relative offset.

I depends on your setup and what is the desired result.
SnapToGrid will not necessarily work if the cubes are not the same dimensions as the grid snap value or if the current location is not a multiple of the grid value (assuming you need the cubes to perfectly snap to each other without any gaps or overlaps).

If you do need them to perfectly snap right next to each other regardless of cube dimensions or location then you could try something like:

Normal * CubeSize + A.GetWorldLocation
If you need them to have a specific amount of gap between them then add it to the cube size.

If we are talking about a different shape than a perfect cube or if there is rotation involved then it can get a bit more complicated.