left and right player movements restricted to a circle

i’m build a boss fight level where there is a cirlce platform
this is what work:
if i press up arrow the player go torwards the boss
if i press down arrow the player go in the opposite site (as you can see in the image)

how can i move the player (left and right arrow ) with mathematical circle equation, to move the player around the boss??

Thanks in advance :slight_smile:

I think you have the right idea, with XZradius. One trick to programming is to set up your personal variables that describe what you want. Change them based on how you’re thinking of the problem. Then, “apply” them to the object.


float playerAngle; // 0 to 360. Angle, from center, of player
float playerRadius; // same as your XZradius

Left/right arrow keys add and subtract from the player angle. Very easy, it’s just a number.

Then, don’t use translate or rotateAround, or anything that moves the player form where it was. You know the angle from the center and the distance, so just put the player there. This is a little tricky,

// how far the player is. This is straight North, which is 0 degrees:
Vector3 toPlayer=Vector3.forward*XZradius;
// now spin it to the correct angle:
toPlayer = Quaternion.Euler(0,playerAngle,0)*toPlayer;

// now start it from the center:

Quaternion.Euler isn’t as bad as it looks. It’s just the way you “make” an angle. Multiply (angle times Vector3) is the way you spin a vector by an angle. But, if you’ve never worked with standard (non-Unity) vector math – like Intro High School Geometry – this will probably still be confusing.