public float SetParentRelativeRotation(Vector3 position, Furniture parent) { Vector3 parentCenter = parent.Center(); rotation = 0f; int lookDirectionIndex = alignTo.IndexOf(parent.type); FacingDirection direction = relativeLookDirection[lookDirectionIndex]; switch (direction) { case FacingDirection.Toward: if (position.x >= parent.FrontRight().x) { rotation = 270f; } if (position.z >= parent.FrontRight().z) { rotation = 180f; } if (position.x < parent.FrontLeft().x) { rotation = 90f; } break; case FacingDirection.Away: if (position.x >= parent.FrontRight().x) { rotation = 90f; } if (position.z < parent.BottomLeft().z) { rotation = 180f; } if (position.x < parent.BottomLeft().x) { rotation = 270f; } break; case FacingDirection.Forward: rotation = parent.rotation; break; case FacingDirection.Right: rotation = parent.rotation + 90f; break; case FacingDirection.Backward: rotation = parent.rotation + 180f; break; case FacingDirection.Left: rotation = parent.rotation + 270f; break; default: break; } if (rotation >= 360) { rotation -= 360f; } return(rotation); }