9/26 - 9/29
- Nathan Matarazzo
- Sep 28, 2023
- 2 min read
This week I continued my work on my arcade machine project. Firstly, I noticed that when I shot the ball, although the code was right, it would slightly differ in the force added to the ball from time to time. I immediately knew that this was because of Unity's physics engine, and the momentum that the ball carried from the previous shot attempts. I added a line of code (ballrb.velocity = new Vector2(0f, 0f); ) for when the ball is in the player's hands in order to reset the force on the ball, so it wouldn't carry any other forces that would disrupt the shot function.
Next, I added a score function to keep score. Whenever the ball makes contact with the score trigger, which is located just underneath the rim, it adds 2 to the 'OneScoreKeeper' float variable, unless the player was standing in the 3 point zone, which would then mean that 3 would be added to that variable instead. I then put a Debug.Log(OneScoreKeeper); line into my code to view the value of the score keeper variable in the console tab.

I then found the function I would be using for the x-power and y-power of the function that would add force to the basketball. I used a distance function to find the x-value of the position of the basketball within the code. Initially using a guess-and-check method, I found that when the x-value of the ball = 400, the force on the x-axis should be 310 to make the ball go through the hoop, and when the x-value is directly underneath the hoop, the force on the x-axis should be at 0. Plugging these two values into desmos graphing calculator, using the x coordinate as the x, and the power as the y, and then using point-slope form to find the line of best fit between the two points, I calculated the constant and coefficient of the force function.

With a little more tweaking, I settled on these functions for the coding of the x and y forces enacted onto the ball for the shot to go in every time, more or less. The rng (or random number generator) will be a different range of values for every playable character, and will be used to affect the shot. Better shooting characters will have a lower range for their rng, while worse shooting characters will have a larger range, so they have a higher chance of their rng generating a value which would seriously affect the shot, each time they shoot.

Furthermore, this week I almost deleted my whole project when I tried to move the project folder from the local disk, to my student google drive. Luckily, I had made a backup literally minutes before doing this, so I was able to recover pretty much everything. With the help of Scott Campbell, my classmate, I created a GitHub account and a repository for my project that will serve as a backup, and another way for me to track my progress.



Comments