• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking

Making a circle - advanced challenge

Picture
Legend has it that when the famous painter, Hans Hobein, applied to be court painter to Henry VIII he was interviewed by the King.

The King simply asked him to draw a circle on the ground.  He did so, and the circle was so perfect that he got the job.

Drawing a circle has always been a test of skill :)

How to do it

That variable 'howFar' is not very interesting.  It just sticks at one.

Let's make it an angle counter, ticking up from 0 to 360 and then back to one again.
Picture
Picture
Now you need to get your maths on.  You want to work out the x and z positions on the plane of a perfect circle around the origin.

Remember sin and cosine?  Remember what they do?

You can get Unity to tell you what the sin and cosine of the angle are.  The functions you need are:
Mathf.Sin(myAngleInRadians) and Mathf.Cos(myAngleInRadians).  There's only one problem, it wants the angle in Radians.   You may know how to do that, but once again, Unity makes it easy.

To get the value of an angle in radians, take your value in degrees and multiply it by Mathf.Deg2Rad

Can you do it?

It's very satisfying when it works.  I promise.

Powered by Create your own unique website with customizable templates.