An ambitious final project for my scripting for games class at UTD that takes the usual two-player coop game and adds a twist to it. There is a 3d player that exists within a room of randomly generated objects and a 2d player that exists within the screen plane that must jump on the objects to complete each level. The 2d player can interact with 3d objects as if they were platforms in the 2d world. The game’s objects include basic platforms that interact with the 2d player, kill boxes, the goal, and mirrors and portals, which the 2d player can interact through as if they lead to another space. In my code, the 3d player is referred to as “cleric” and the 2d player is referred to as “wisp”.
Wisp Player Controller
The wisp player controller was riddled with challenges. In order to get the correct normal in this simulated 2d environment, I used raycasts aimed from the camera to the next position of wisp to determine if it would impact one of the interacting objects (which have tags to signify the way they interact). If one is hit, additional raycasts are used to determine the nearest perspectively projected edge to wisp by finding the 3 vertices of the hit triangle of the object’s mesh, calculating the distance to each line projected into the screen plane, then checking if there is a closer triangle in case the movement was too fast. The perspectively projected edge gives the normal, which can be used to reduce wisp’s movement to prevent it from entering the object.
Portals/Mirrors
While these portals do not allow cleric to travel through them, they do allow wisp to interact with anything seen through them. By using Unity’s physical camera settings, I was able to adjust the position, lens shift, focal length, and clipping planes to allow a perfect reflection or continuation of what the player sees. This would require additional cameras to simulate the similar effect on additional mirrors or portals seen through a mirror or portal, but is not currently implemented.
Mirrors and portals continue raycasts sent by wisp’s physics checks, and can even bounce multiple times. The script itself has 3 different modes, repeat, once, and mirror. Currently it only functions as repeat for either portal option.