Hi,
I struggle at teleporting a RigidBody and respect the offsets in position and rotation between portal and RB. See this drawing.
I am entering portal A at the red dot in the red arrows direction.
Expected: Leaving at portal B with the red arrows direction at red arrows position.
Actual: Exiting at the blue dot with the blue direction.
Below is my script, which I worked together with some google help and YouTube tutorials but seems like I got lost somewhere and I can’t figure out how to set the offsets correctly. Where is the fault in here?
Vector3 portalToObject;
Vector3 rbVel;
Vector3 rbVelAng;
Quaternion quatDiff;
public void Teleport(GameObject objectToTeleport)
{
portalToObject = portalA.position - objectToTeleport.transform.position;
quatDiff = Quaternion.Inverse(objectToTeleport.transform.rotation) * portalA.transform.rotation;
rb = objectToTeleport.GetComponent<Rigidbody>();
rbVel = rb.velocity;
rbVelAng = rb.angularVelocity;
rb.isKinematic = true;
rb.MoveRotation(portalB.rotation * quatDiff);
rb.position = portalB.position + portalToObject;
rb.isKinematic = false;
rb.velocity = rbVel;
rb.angularVelocity = rbVelAng;
}
I am probably doing something wrong with the rigidbody velocity stuff, but I can’t even get the position and rotation right after the teleport and am kinda lost now…