# Changing the RotateAround center point dynamically

• Black circles are static
• Red - player
• Blue line - path

I'm trying to achieve a constant movement of the red dot like on the image below. For now, I have something like:

void Update(){

target = firstCircle; // here I need to perform some calculations
this.transform.RotateAround(target.transform.position, Vector3.forward, speed * Time.deltaTime);

}


As you can see in the code, it rotates around the upper circle now. I need to switch the target variable to the secondCircle when the player comes back to it's initial position (or is near it).

I came up with something like:

if(Mathf.Abs(Mathf.DeltaAngle(360f,this.transform.rotation.eulerAngles.z)) < 5f)
//change target


and it works but has two issues. First - the epsilon value. If I set it to 5f the above if is true like 7 times (depending on the player's speed). Of course I could make a lock to run it only once per cycle, but there's a second problem. If the object is moving too fast, the if will be false each time, cause the speed-step is always higher than the epsilon.

How is this done in 'gravity' games like AngryBirds when the bullet changes it's attraction point?

• Those games actually use physics, here's what you could do: gamedev.stackexchange.com/questions/140008/… with two of those "planets" and your "player", it's actually pretty easy to do this. You just need an initial speed, and no friction while it goes around the objects (I've this same system in my game and the "bullets" my ships fire can recreate the exact same situation). – John Hamilton May 23 '17 at 13:41