More Trigonometry, Class Diagrams & Further Research

Expanding on the research assigned to us last week, todays class covered its practical use within games.

Refer to my previous post for the basics of Trigonometry and SOHCAHTOA.

Research – Trigonometry & Class Diagrams

Within Unity, x and y movement in a 2D project is controlled by sine and cosine.

  • Sine = ratio of Y movement
  • Cosine = ratio of X movement

Cosine(angle) = X / distance : X = Cosine(angle) * distance

Sine(angle) = Y / distance : Y = Sine(angle) * distance

Here is an example of this being used in engine to control a spaceship similar to the one we were using before Christmas.


Here is exactly the same thing but using Unity’s built in functions.


Really does make you appreciate how much work Unity does for you in the background.


Radians are an alternative unit to using degrees, they are more commonly used in code. One radian is the angle covered by wrapping a circles radius around its own circumference.

Pi radians is 180º, so 2 Pi Radians is a full rotation 360º

Radians = degrees / 180 * Pi

Degrees = Radians / Pi * 180


Class Diagrams

These are now making a little bit more sense after some context AND having some of the names of things changed around.

A class diagram is like a blueprint or a recipe for an instance. We’ve seen these already, all C# files in Unity are class files (recipes).


Here is an example given in class. Transform is the class name, in the second box we have position, rotation & scale. This made more sense when Ant said consider this box as variables rather than the attributes tag the example had online, and with any variable we need to declare its data type. In this example its Vector3. The third box I was told to consider as functions rather than operations, this should include parameters and data types. In this example its just void which we’re used to seeing.

A tip provided to us was to write attributes & operations (variables and functions) as we would in code. So variables are written lower case and functions are written Camel case. To help myself in future I’m posting a second example given to us. One that we’re used to seeing from the project before Christmas.


Thanks to these, class diagrams make a lot more sense than they did last week. All that was needed for me to understand it was to change the names around to something I’m more familiar with.




Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s