Hello, I'm trying to make a dragon fly around in a circle at a set radius (ideally around the player). I've tried to use RotateAround like this: Code (csharp): var degrees = 10; var circleMe : Transform; function Update() { transform.RotateAround (circleMe.position, Vector3.up, degrees * Time.deltaTime); } This gets it to orbit around the player, but eventually the actual rotation of the dragon becomes off and it appears as if the dragon is flying backwards. Also the radius gets larger and larger as i move up and down on the terrain of my map. Is there a way to make it fly in a circle of a set radius, regardless of my players Y position? I would ideally want it to fly around while having its head (fixed) facing the player at all times. I'm not the best with Vectors and Math, so any help would be greatly appreciated. Thanks in advance! -Anthony
The problem is that you're increasing the transform values by deltatime which is why your dragon seems to fly off away from what it's supposed to be circling. I think anyway! Try having a seperate var for Vector.up and a value assigned to it that doesn't increase via delta time ut fo the tansform..
Here! I modified the LookAt script to autmatically do what you want. Attach it to the object you want orbiting and for the target select the object to be orbted. Code (csharp): var target : Transform; private var distance = 5.0; private var xSpeed = 10; private var x = 0.0; private var y = 0.0; function Start () { var angles = transform.eulerAngles; x = angles.y; y = angles.x; // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation = true; } function FixedUpdate () { if (target) { x += xSpeed * Time.deltaTime; var rotation = Quaternion.Euler(y, x, 0); var position = rotation * Vector3(0.0, 0.0, -distance) + target.position; transform.rotation = rotation; transform.position = position; } }
You could of course do it the easy way? Make an object that a) follows your character and b) rotates on the spot. Then just make the dragonfly a child of this object but shift it's position over to the side a bit. Radius would be defined by the local position of the child, and LookAt() not needed... Just a thought.