Monday, February 26, 2018

2/26/18 - Math Inside the Player Script

This week for math I will be looking at the player script for Chandler and I's game. This script contains a fair amount of math in it.



To start we will look at the variables that are used inside of this script. There are alot. At the top we have the basic player stats, such as health, maxhealth, and level. Below that we have the Misc Player info, which could be brought into play later in development. Below that we have a misc placeholder for the healthbar. Then we have all of the Projectile Variables, such as the power, timebetween shots, and more. These are used to store all of the information needed when the player is firing a shot. After that we have all of the player movement variables such as speed, Camera variables, and more. These will all be used later on in the scripts, and can be set in the properties of the object so you do not have to edit the script when you want to make a change.











Next, we have the start function. This will run when the game starts. It will first set the projectile type to the most basic type, as thats what you start out with. Next it sets health to mac, and sets the healthbar to the proper gameobject. It then sets all of the projectile stats to 0, and assigns the camera to the Cameraholder.





 In order to have more options with the camera for Debug reasons, I followed an online tutorial for enumerators, which is a set of rules to follow, which can be switched. I set up four camera types: Lerp, MoveTowards, AccelDecl, and Acceleration.

The different Camera types were used in the switch function below.



What is happening in this switch function is that based on which option is selected (out of the four above,) it will change the way the function is called. For example, if the camera type is set to lerp, it will use the CameraMovementType.Lerp case, which will make the camera lerp between positions.


 At the beginning of the Update function, there is a Vector3 being set to the mouse positions on the screen, and then setting variable mouse, to that position. It is then rotating the aim guide to point towards the mouse, so you know where you are shooting.
The disFromCamera Vector3 is getting how far away the player is from the camera. It is followed by several if statements checking the distance, and setting whether the camera is moving or not. If the camera is moving, it will call the CameraMovement function.
After that, its setting the projectile spawn to the players locations, and also setting the healthbar to the current health.

1 comment:

  1. Thank you for sharing. I unfortunately can't see the pictures you included but I can get the gist of what you are working on. I appreciate you sharing your learning and being specific. This is what I want to see! Good job.

    ReplyDelete