} //returns self public Vector3 GetPosition(Space relativeTo = Space.Self) { //gets position with specified space if (relativeTo == Space.Self) { if (factorScale) { if (offsetScale != 0f) //ALL WORKS! { return(Linking.InverseTransformPoint(operationalPosition, parentPos, parentRot, parentScale) / offsetScale); } else { return(Vector3.zero); } } else { return(Linking.InverseTransformPoint(operationalPosition, parentPos, parentRot)); //WORKS } } else { return(operationalPosition); //WORKS! } }
public override Vector3 GetTarget() { Vector3 target = Vector3.zero; if (space == Space.World) { target = rigidbody.velocity; } else if (space == Space.Self) { target = (parent.TransformPoint(Linking.InverseTransformPoint(parentPos + rigidbody.velocity, parentPos, parentRot)) - parent.position).normalized * rigidbody.velocity.magnitude; } return(target); }
} //returns world public Vector3 SetPositionLocal(Vector3 position, Space relativeTo = Space.Self) { //sets position and returns local position if (relativeTo == Space.Self) { return(position); } else { if (factorScale) { return(Linking.InverseTransformPoint(position, parentPos, parentRot, parentScale /* * offsetScale*/) / offsetScale); //WORKS! } else { return(Linking.InverseTransformPoint(position, parentPos, parentRot, parentScale).Divide(parentScale)); //WORKS! } } } //returns self
public override void SetPrevious() //WORKS! { if (factorScale) { if (offsetScale != 0f) { previous = Linking.InverseTransformPoint(operationalPosition, parentPos, parentRot, parentScale) / offsetScale; previousDirection = Linking.InverseTransformPoint(operationalPosition, parentPos, parentRot) / offsetScale; } else { previous = Vector3.zero; } } else { previous = Linking.InverseTransformPoint(operationalPosition, parentPos, parentRot, parentScale); previousDirection = Linking.InverseTransformPoint(operationalPosition, parentPos, parentRot); } }
//inspector methods public override void Switch(Space newSpace, Link newLink) { //switch spaces and link Vector3 originalPositon = position; Vector3 originalLocalPosition = localPosition; if (space == Space.World) { if (newSpace == Space.Self) { if (newLink == Link.Offset) //world > offset { space = Space.Self; link = Link.Offset; //auto keep offset if (factorScale) //factor scale { SetToTarget(); Vector3 from = Linking.InverseTransformPoint(position, parent.position, parent.rotation, parent.scale * offsetScale); Vector3 to = Linking.InverseTransformPoint(originalPositon, parent.position, parent.rotation, parent.scale * offsetScale); value += to - from; } else //dont factor scale { SetToTarget(); Vector3 from = Linking.InverseTransformPoint(position, parent.position, parent.rotation); Vector3 to = Linking.InverseTransformPoint(originalPositon, parent.position, parent.rotation); value += to - from; } } 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; position = originalPositon; } else { if (newLink == Link.Match) //offset > match { link = Link.Match; } } } else if (link == Link.Match) { if (newSpace == Space.World) //match > world { space = Space.World; position = originalPositon; } else { if (newLink == Link.Offset) //match > offset { link = Link.Offset; //auto keep offset if (factorScale) //factor scale { SetToTarget(); Vector3 from = Linking.InverseTransformPoint(position, parent.position, parent.rotation, parent.scale * offsetScale); Vector3 to = Linking.InverseTransformPoint(originalPositon, parent.position, parent.rotation, parent.scale * offsetScale); value += to - from; } else //dont factor scale { SetToTarget(); Vector3 from = Linking.InverseTransformPoint(position, parent.position, parent.rotation); Vector3 to = Linking.InverseTransformPoint(originalPositon, parent.position, parent.rotation); value += to - from; } } } } } }