Dash mechanic update

Having made a dash mechanic for Able, it then made sense for her to have a stamina system in place, as a child wouldn’t be able to dash and run for a continuous amount of time. So, with some help from James, I created a player controller for Able which gives her a max stamina of 100, and in the update method of the script, it will regenerate at a rate of 7 per second if it is less than a value of 100. screen-shot-2017-03-02-at-14-40-13

The code then needed a small augmentation for it to include the depletion of stamina when there is a dash. Before the dash happens in the start method, using the ‘if’ function, it will ask whether Able’s stamina is above 50, if so the player will be able to use the ‘r’ key to dash. When Able’s stamina is below 50 the player will not be able to dash and will have to wait for it to regenerate. The stamina regeneration and depletion may have to be augmented at later stages of development. screen-shot-2017-03-02-at-14-40-20

Progress!

With Unity’s camera automatically following the whole screen, I needed to create a script that allowed the camera to follow the player so the game can play correctly. Firstly, the script gets added to the camera so any changes added are applied. The LookAt function is used in the script along with a private offset of Vector3 (Z axis). In the engine, the camera script shows the LookAt function with a variable, so the ‘Player’ item in the game gets added to this so the camera will now look at the character and follow it when it moves. On it’s own, the camera would be in the exact same position as the character in all three axis, but with adding the offset means the camera follows the character at a position where it can be seen. Thankfully this script didn’t need fixing!

screen-shot-2017-02-23-at-14-16-34

When playing the game in the engine, the scale of the camera can be changed (how far it zooms into what it is looking at), so this can be changed for different scenarios of the game. For example, when encountering the big bad woof, the camera will need to zoom out so the whole scene can be seen.

screen-shot-2017-02-24-at-12-24-38

The next script to tackle is the dash mechanic. This will be done by a test within the script and creating a new function, sprintTime. It will use the input ‘GetKeyDown’ which will determine whether she is dashing or not, and the time is divided by 1 so essentially will be sprinting but only for 1 second, simulating a dash. On the first try, pressing ‘r’ caused the character to speed up to the speed of 9f (the dash speed) but continue at it after releasing the key. So, I again used the ‘GetKey’ function, but this time for when the ‘r’ key is up (not being pressed) the speed will return to its regular value. As Able can both sprint and dash, a stamina system will be needed to regulate how many times she can perform these actions. I attempted this system during the week but encountered problems in doing so.

screen-shot-2017-02-23-at-14-16-22

This link is a short video showing a working prototype:

Simplifying code – 20/2

Taking work which I held on to from my first year, I created a basic movement script for the player. Separately I created updates for moving the player left and right by changing the co-ordinates of their position, and them being positive for the right and negative for the left. For these changes to happen, in the update part of the script, I used the Input.GetKey function so when a named key is pressed, it will move the player.

screen-shot-2017-02-20-at-13-16-08

To make this piece of code simpler I am now using the function Input.GetAxis function which has built controller mapping for unity, them being A/D and Left/Right. So, using a single line of code using the horizontal axis the player now moves more smoothly which will be more beneficial when adding the animations to the character. Also, the function also can be used for analogue stick control if we choose to change to an Xbox/Playstation controller for the final demo.screen-shot-2017-02-20-at-13-17-24

With the original jump script having a few bugs to it, I decided to change the functions used to make the player jump. It originally used the transform.Translate function to move the character to a new co-ordinate along the vertical axis, then the player will fall due to having a rigid body, simulating a jump action. However, this method for creating the jump makes the movement look too quick compared to how a jump would normally look in game. So, I changed the function so it adds a force to the character rather than moving it to a new location, creating a better and more natural jump. I was also able to fix the bug of the character jumping again in mid-air.

screen-shot-2017-02-20-at-13-32-29

For this I used true or false statements and collisions. The function ‘canJump’ determines whether the character is able to jump into the air, so for the update where the character is projected into the air, ‘canJump’ is set to false meaning they are unable to jump again until grounded. I then ran into another bug in that upon playing the character could only jump once, so again using the ‘canJump’ function, if the player collides with the game floor (which is tagged as ‘Floor’ in Unity0, the statement is set to true so the player is able to jump again.