I guess this is a noob math question…
I want to “align” one object to another. Says ObjA to ObjB. ObjB has an anchor point. After alignment the anchor point of ObjB should be on the lower/center point of ObjA.
Example (ObjA = blue, ObjB = cyan):
My code is:
var boxCollider = GetComponent<BoxCollider>();
var lowerCenterPos = new Vector3(transform.localPosition.x, transform.localPosition.y - boxCollider.size.y / 2f);
var slotDisplacment = -equipmentSlot.Slot.transform.localPosition;
equipmentSlot.transform.rotation = transform.rotation;
var root = equipmentSlot.transform.root;
root.transform.position = lowerCenterPos + slotDisplacment;
This works until objects (ObjA or ObjB) are rotated. If they are rotated my slotDisplacment is wrong because it’s in world coordinates. And
root.transform.position = lowerCenterPos + slotDisplacment;
is wrong then.
How do I convert my offset with respect to the orientation of ObjA?
Thx,
Sven
