[ad_1]
When the Player walks via the portal (OnCollisionEnter), the Player (different) is teleported to the otherPortal’s location.
Sure sufficient, the Player’s place modifications however their Orientation and Velocity stay the identical.
To repair this, I’ve opted to alter the Player’s Y rotation to match the Z rotation of the otherPortal (these portals are planes so their rotation on the x-axis is 90 levels).
// Change Position (different.place = otherPortal.positionXZ + otherRoom.positionY)
different.rework.place = new Vector3(otherPortal.rework.place.x,
otherRoom.rework.place.y,
otherPortal.rework.place.z);
// Change Orientation (different.rotationY = otherPortal.rotationZ)
different.rework.rotation = new Quaternion(different.rework.rotation.w, different.rework.rotation.x,
different.rework.rotation.y - rework.rotation.z + different.rework.rotation.z,
different.rework.rotation.z);
// Change Velocity ("bump" participant ahead)
Rigidbody otherRB;
if(different.gameObject.GetComponent<Rigidbody>() != null)
{ otherRB = different.gameObject.GetComponent<Rigidbody>();
otherRB.velocity = new Vector3(0,0,0);
otherRB.rework.Translate(Vector3.ahead * 4);
}
I’m subtracting myPortal’s rotation to set the Player’s rotation relative to the World, then I add again within the otherPortal’s rotation.
After I rotate the Player, I give them a slight little “push” to get them via and make the transition a little bit bit extra seamless.
However, the rotation transformation would not appear to be working in any respect and I cant work out why. The participant is getting pushed, however somewhat than being pushed ahead, they’re pushed again?
[ad_2]