Hello all. I have a huge request for help in solving my problem. I’m trying to make the system attaching and detaching objects using nodes.
Objects that are to be attached to the node, have also Nodes.
My problem is that I can not rotate the object so that both Nodes overlap.
This is what i have for now:
Ray _ray = _mainCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
if (Physics.Raycast(_ray, out _rayHit, 3,nodeLayer))
{
if (rayHitNode != null && Input.GetKeyDown(KeyCode.Mouse0))
{
_attachSystem.AttachObject(whatObjWeCarry, rayHitNode);
}
}
public void AttachObject(GameObject objectToAttach, GameObject hitNodeObject)
{
if (string.Equals(_objToAtt, _nodeWeGet) && hitNodeObject != null)
{
objectToAttach.transform.SetParent(null);
objectToAttach.transform.SetParent(hitNodeObject.transform.root);
target = objectToAttach.transform.GetChild(0).localRotation;
node = hitNodeObject.transform.rotation; objectToAttach.transform.rotation = Quaternion.Inverse(target) * node;
}
}
I hope I was able to explain what I mean, because, unfortunately, but English is not my native language.
