public static void PostTeleportation(Rigidbody body, List <Rigidbody> jointAttached, bool motionKept, PreTeleportationValues bodyValues, PreTeleportationValues[] attachedBodyValues) { body.isKinematic = false; body.freezeRotation = false; body.constraints = bodyValues.constrains; if (motionKept) { body.velocity = bodyValues.velocity; body.rotation = bodyValues.rotation; body.angularVelocity = bodyValues.angularVelocity; } else { body.velocity = Vector3.zero; body.rotation = Quaternion.identity; body.angularVelocity = Vector3.zero; } if (jointAttached != null) { int i = 0; foreach (Rigidbody attachedByJoint in jointAttached) { PostTeleportation(attachedByJoint, null, motionKept, attachedBodyValues[i], null); i++; } } }
public static void PreTeleportation(Rigidbody body, List <Rigidbody> jointAttached, bool motionKept, out PreTeleportationValues bodyValues, out PreTeleportationValues[] attachedBodyValues) { bodyValues = new PreTeleportationValues(body, motionKept); body.isKinematic = true; body.freezeRotation = true; attachedBodyValues = null; if (jointAttached != null) { List <PreTeleportationValues> preValues = new List <PreTeleportationValues>(jointAttached.Count); foreach (Rigidbody attachedByJoint in jointAttached) { PreTeleportationValues jointValue; PreTeleportationValues[] useless; PreTeleportation(attachedByJoint, null, motionKept, out jointValue, out useless); preValues.Add(jointValue); } attachedBodyValues = preValues.ToArray(); } }