Before updating to Windows 10 you may need to return your Pro license. More information here

How do you orbit an object over a point on the map in a circle, with the object facing in the correct direction?

I have created a helicopter over terrain (say at y=50). I have a terrain that is 500x 500. I would like the helicopter to orbit with a radius of 50 (available for change above the point in a variable). I would like to have a speed variable that I can set set based on how it looks.

I need it to orbit at the same altitude in a circle in the center of the map (250,0,250), with the helicopter rotating to always face forward on the flight path.

I have some orbiting code here that makes the helicopter go in a circle, but I do not know how to face the helicopter forward along the flight path. I am not fully happy with the code, as when I tweak settings it also seems to make the circle elongate and have strange behaviour based on various combinations of speed, angle rotation, and radius. Additionally, this code does not orbit around the point but in a circle to the north of it (along the z axis forward). Please recommend some easier code or tweaks!!!! Thank you!!

 #pragma strict
 var speed = .5; // speed .5 seems to work, with radius 20, and change angle 10, but it seems eliptical
 var radius = 20.0;
 var angle = 0.0;
 var changeAngle=10; // change the Angle around the cirlce
 var StartX = 250; // origin points for circle
 var StartY =250;
 var x=0.0;
 var y=0.0;
 function Update () {
 // this is the code to move it in a circle
     x = (radius * Mathf.Cos(angle));
     y= -(radius * Mathf.Sin(angle));
     transform.Translate(x*speed*Time.deltaTime,y*speed*Time.deltaTime,0); // this seems to work moving in circle of right radius
     angle = angle + changeAngle* Mathf.Deg2Rad * speed*Time.deltaTime;
 //Need some lookat code here
more ▼

asked Mar 22, 2013 at 02:01 AM

avatar image

3 1 3 4


Mar 22, 2013 at 02:08 AM Benproductions1
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

In Unity there are a number of simpler ways to accomplish the same task. Attach the following script to your helicopter. Set the pivot to the position in the air around which you want your helicopter to rotate. Place your helicopter at one position on the circle out from the pivot.

 var speed : float = 30.0;
 private var pivot : Vector3 = new Vector3(0,50,0);
 function Update () {
     transform.RotateAround(pivot, Vector3.up, speed * Time.deltaTime);

more ▼

answered Mar 22, 2013 at 05:53 PM

avatar image

115k 27 79 261


This is exactly right! Thank you for the help!

Mar 23, 2013 at 01:23 PM me1501

If you are satisfied, click the checkmark next to the answer to mark it as having been answered.

Mar 23, 2013 at 03:59 PM robertbu

Thanks robertbu, I also found this helpful. I was overcomplicating it in my thoughts, as I was unaware of RotateAround function

May 22, 2014 at 10:48 PM Erisat
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Mar 22, 2013 at 02:01 AM

Seen: 2881 times

Last Updated: May 22, 2014 at 10:48 PM