I’ve finally gotten to start programming. I took Patrick’s Unity Project and started by putting the current level layout in, and just ran around the level and tweaking Pan’s jump height and speed, as well as the level in terms of gaps and heights for jumps.
The bits of code I needed for this first part of the level (in addition to the character-controller that patrick had made) was the interactable lever which should cause the claw holding the box to open and make the box fall.
The first course of action was to make the player controller recognize that Pan is within reach of the lever. So I gave the lever a simple BoxCollider2D, which is slightly larger than the lever itself and made it an IsTrigger.
Then I attached a script with an OnTriggerEnter2D method, that checks whether the other collider has the tag “Player” on it. If it does, so if the player is within reach of the lever, it will tell that to the PlayerInteractScript, giving the GameObject of the lever to it. This Script can and will be attached to all interactables, as it doesn’t specifically targets the lever. The Script also contains an OnTriggerExtit2D method, which deletes the reference to the lever when the player leaves the area.
Next, or rather parallelly, I attached a new PlayerInteractScript to the Player object. This script will probably be merged into another script, but I wanted to keep it separated for now, as not to mess too much with Patrick’s script.
This Script holds a variable that contains the current interactable within Pan’s reach (GameObject interactable), and a method to set this variable (void NewInteractible). It also currently contains the input method for interacting with the object, as well as a hardcoded list of things that happen for each interactable (currently just the one lever).
Other than that I made a mockup animation for the claw holding the box (as referenced in line 41) which took me considerable effort, as I’ve not worked on animations before, and I had trouble with having a start and end position for the claw, before and after the animation plays.
The result can be seen in this short video (turn on sound for german electropop)