During this past week, I spent my time fixing and updating numerous mechanics for the player and camera.  One of the first things that I worked on was updating the player from a table to a class in Lua, because this would enable me to keep the player’s variables protected and all of its functions and mechanics in the player file, not in main.  In addition, by passing in all the data needed for the player when creating it with a constructor, I could make an update function specifically for the player.

Moving on, to one of the biggest challenges I faced this week: getting the camera to follow the player without rotating with it and transitioning to a second camera for a cut scene.  At first I had the camera attached to the player as a child, which allowed the camera to follow the player and rotate with it, but it increased the difficulty of manipulating the camera directly.  In addition, I was also having difficulty removing the camera from the player and making it pan around the level to simulate an opening cut scene.  However, after doing some research and playing around with the camera I came to realize I was going about this the wrong way.

The first thing I was doing wrong was only using one camera, when instead I should have been using two of them, and the second problem was having the camera attached the player as a child.  In addition, I came across something in Polycode which became a game changer: Polycode does have a “getPosition()” function, but you can only call “getPosition()” on each individual transform component of an entity. For example:

local x, y, z = entity:getPosition().x, entity:getPosition().y, entity:getPosition().z

After learning this I was able to have the player_camera follow and look at the player without having it attached as a child, and I could do the same thing with the main_camera, but I just had the main camera look at the player and stay stationary.  By now, I had already solved most of my problems, and all that was left to do was setup a cut-scene. This was fairly simple, for all I did was setup a time-based event trigger which toggled the main_camera on and the player_camera off, create a function to make the main_camera move to different locations based on time, then toggle the main_camera off and player_camera on when the cut scene was complete.  In the screenshot above, you can see the player through the main_camera during the cut scene.

– Logan Acree

Leave a comment