public override void Switch(Space newSpace, Link newLink) //WORKS! { Vector3 originalDirection = direction; Vector3 originalLocalDirection = localDirection; if (space == Space.World) { if (newSpace == Space.Self) //world > self { space = Space.Self; //auto keep offset value = offset.ReverseRotation( Linking.InverseTransformEuler(Quaternion.LookRotation(originalDirection), parent.rotation)) * Vector3.forward; } } else if (space == Space.Self) { if (newSpace == Space.World) //self > world { space = Space.World; value = direction; } } }
public Quaternion SetRotationLocal(Vector3 rotation, Space relativeTo = Space.Self) { if (relativeTo == Space.Self) { return(Quaternion.Euler(rotation)); } else { return(Linking.InverseTransformEuler(Quaternion.Euler(rotation), parentRot)); } }
//inspector methods public override void Switch(Space newSpace, Link newLink) { Quaternion originalRotation = rotation; Quaternion originalLocalRotation = localRotation; if (space == Space.World) { if (newSpace == Space.Self) { if (newLink == Link.Offset) //world > offset { space = Space.Self; link = Link.Offset; //auto keep offset SetToTarget(); value = offset.ReverseRotation(this, Linking.InverseTransformEuler(originalRotation, parent.rotation)); } else if (newLink == Link.Match) //world > match { space = Space.Self; link = Link.Match; } } } else if (space == Space.Self) { if (link == Link.Offset) { if (newSpace == Space.World) //offset > world { space = Space.World; rotation = originalRotation; } else { if (newLink == Link.Match) //offset > match { link = Link.Match; } } } else if (link == Link.Match) { if (newSpace == Space.World) //match > world { space = Space.World; rotation = originalRotation; } else { if (newLink == Link.Offset) //match > offset { link = Link.Offset; //auto keep offset SetToTarget(); value = offset.ReverseRotation(this, Linking.InverseTransformEuler(originalRotation, parent.rotation)); } } } } }
public override void SetPrevious() { previous = Linking.InverseTransformEuler(operationalRotation, parentRot); }