Day 4 - Progress

Before I started working on my first target I noticed something in my code I didn't like, regarding the freezeMovement boolean. This needed to be fixed first!

Fix freezeMovement
Whenever the Update function of the CharacterMovement script checked for player input and the outcome was less than or greater than zero a function was called. In this function a check was performed, whether freezeMovement was false, if so the movement script started. But I did this separate for each movement function (see image below) and now I was going to add two more for the rotation. 











This unnecessary (and ugly) code repetition had to go!

So I moved the boolean check for freezeMovment to the Update, so now the first thing that get's checked is if the character's movement is frozen, if not the code checks if there's player input and then the function gets called. This way the system only needs to check the freezeMovement once (see image below).

























Character rotation based on mouse input
So because the player has a first person view it doesn't feel natural to make the character rotate by pressing the <- and -> buttons. It feels way more natural to have the rotation based on the mouse input. 

For the character's horizontal rotation I used the excisting code for the horizontal rotation, only I changed the xInput to mouseX. So instead of basing the rotation on the keyboard input it now reacts to the mouse input.

Then I changed the excisting character rotation to strive movement. Also a quick and easy fix. All I had to do was change the rigidbody's Rotate into a Translate and move the input from float y to float x. Also I changed the rotateSpeed to moveSpeed, because 20.0f was a little over the top! 

I also want the player to be able to look up and down. Therefor I created vertical rotation. Now this was a little different from the other movement and rotation scripts, because I didn't want to rotate the character, I only wanted to rotate the camera. Also I created a range for the up and down rotation.

The cursor is locked within the boundries of the screen. I want to change the cursor texture in the polishing stage.

Challenge system

For the challenges I first had to decide on an approach for the challenge system. I could either choose to create new scenes for each challenge or implement the system in the excisting scene using a canvas. I decided to go with the canvas approach, to avoid transition screnes.

Next I had to decide on an approach on creating the code. I could either create one large script or I could create new scripts for each puzzle. I chose the second option, because I want to have the possibility to create larger challenges (which ofcourse require more code) and by writing only one script this might get quite messy. Each challenge scripts inherits from the base class which includes the functions Problem, Solution and Help.

My first thought was to build a general challenge system before designing the challenges, but I decided to do it the other way around. The concept for the challenges was still very vague, which made it harder to create a good system. So I'll be working on the design before programming the system.

Challenge design
For my design I came up with a few ideas and decided to work out three of the challenges. I will not post much on the challenge design, because I don't want to spoil too much content.



Comments