- 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?