Home Game Development Unity Portals: Seamless Portals, Match Relative Camera Positions

Unity Portals: Seamless Portals, Match Relative Camera Positions

0
Unity Portals: Seamless Portals, Match Relative Camera Positions

[ad_1]

To create a portal, I already know to get a particular shader, and set the fabric of my portal to a second digital camera, blabla & so on. My code for the Camera place works besides when the rotation of my portals just isn’t equal. I’ve this ingenious system (if i do say so mself).
Get the space b/w myPortal and playerCam, subtract myPortal.place & myPortal.rotation (set to [0,0]), add again in differentPortal.place & differentPortal.rotation.

Here’s a desmos hyperlink to all of the maths->
https://www.desmos.com/calculator/numjnyfljl

float pi = Mathf.PI/180;
float newX, newY, newZ;
float d;    // Distance between Portal and PlayerCam
float phi;  // Angle between Portal and PortalCam
d = Mathf.Sqrt( (playerCam.place.x - portal.place.x)*(playerCam.place.x - portal.place.x) +
                (playerCam.place.z - portal.place.z)*(playerCam.place.z - portal.place.z) );
if(playerCam.place.x >= portal.place.x)
    d = -d;
phi = Mathf.Atan( (playerCam.place.z - portal.place.z) / (playerCam.place.x - portal.place.x) );

newX = differentPortal.place.x - d*Mathf.Cos(phi - portal.rotation.z*pi + differentPortal.rotation.z*pi);
newY = playerCam.place.y + differentPortal.place.y - portal.place.y;
newZ = differentPortal.place.z - d*Mathf.Sin(phi - portal.rotation.z*pi + differentPortal.rotation.z*pi);
rework.place = new Vector3(newX, newY, newZ);

In concept, all this code vomit is meant to match the otherCam’s movement to the playerCam’s movement relative to the portals. This works if the Portals are in line. In my recreation, my take a look at portals are at 90 levels to one another. Sure sufficient, the maths is precisely 90 levels out of part. I flipped Sin & Cos and it labored wonders! (aside from the view from the opposite portal)

This works within the Graphing calculator however not in Unity? The Y positions are advantageous. This works simply advantageous if the portals have the identical rotations. Is it one thing incorrect with my rotation calls?

Bonus Issue: I put the maths into my new Vector3 to avoid wasting on comp time and it made Unity bug out a bit. no thought y

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here