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));
//Latest
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
}
robertu: This is exactly right! Thank you for the help!
– me1501If you are satisfied, click the checkmark next to the answer to mark it as having been answered.
– robertbuThanks robertbu, I also found this helpful. I was overcomplicating it in my thoughts, as I was unaware of RotateAround function
– Erisat