The Trigonometry of Blasters! – Dylan

Blasters are such a staple to video games. Think back to space invaders, that game is almost completely just a simple blaster that moves side to side. That works great if you only want to shoot in a single direction, but what happens when you would like to aim in a full 360 degrees?

Adding the capability to aim in all directions seems simple in concept, but in reality it is remarkably complex, especially for something so common in today’s games. To get this blaster working, I found myself having to add two important parts to my code. One, I need to somehow track the mouses location, and two, I need to make the blaster aim in that direction.  It turns out that the first is much more simple than the second.

Turns out that the “ViewportMouseEvent” Function keeps tabs on the location of the mouse at all times, simple, but effective for my needs. With step one complete, I dove in to part two, rotating my blaster to the direction of my mouse. So, in I bring everyone’s favorite math, Trig!

So, in short I had to calculate the angle difference, in radians, caused by the mouse and then rotate the blaster object by that many radians. Of course in words that seems simple, but in code it involves multiple levels of inter-connectivity in order to keep the code constantly updating the angles, and therefor creating a smooth blasting experience.

 

Photos:

http://zero.digipen.edu/Workshops/2016/VectorMath2.html

 

3 thoughts on “The Trigonometry of Blasters! – Dylan

  1. nscavalieri

    I think your blog could benefit from a little bit more a flow to your writing something that has a defined beginning, middle, and end. However, I think that your images are really great, and your explanation ability is extremely important and efficient. Keep it up!

    Reply
  2. sabrina.schoenborn

    Hey, Dylan! I love where your independent is going! I think its really nice that you explained these concepts in relatively simple terms so that anyone, regardless of their involvement with math, can comprehend them. For the future, I’d love to know more about your own relationships with video games and how that led you to do your own independent. Also, how will this be apart of your end product? Keep it up!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.