Documentation
Intention
To create a mini badminton game using vectors and p5.js.
Process & Mechansim
I wanted to represent the swinging motion of a racquet using a circular motion. To create a circular motion using vectors, I first created two position vectors: an anchor point(center of the circular motion) and a point that rotates around the center(pos). To make a point rotate about the anchor, simply set the velocity to be a vector perpendicular to the vector of the rotating point minus the anchor point at every moment.
I then made the anchor point the base of the handle of the racquet and the rotating point the center of the head of the racquet.
Then, I simply wrote a function that transfers the velocity of the head of the racquet to the ball when the two come in contact with each other.
Next, I added some other basic properties of badminton(a net, a floor, two players facing opposite directions).Finally, I added a jump function, multiplayer controls and instructions, graphics and visual elements, and scores and an ending animation to make the game more complete and fun.
Problems & Discoveries
The biggest problem that I encountered is when I tried to make the racquet swing while a player is jumping. I am unable to synchronize the position vectors of the swinging motion with that of the jumping motion so that they coexist without influencing each other. While working on this project, however, I discovered ways to create circular motion using vectors and to use a hit function to transfer velocity from one object to another when two objects collide.