# Mouse driven circular movement

I want the player to move in a circle. I did the following using cursor keys to move. I simply had the camera looking at 0,0,0 and the player at 0, -5.0, 0. Using left and right had the object moving in a circle with a radius of 5.0

``````var speed = 100.0;

function Update () {

var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
transform.RotateAround(Vector3.zero, Vector3.forward, x);

}

``````

The problem is when in the top half of the screen, left moves right, right moves left, which is counter-intuituve for many, plus it is a digital movement.

I was looking for a similar movement, but the player clicks the mouse, the code works out the angle from 0, 0, 0 and moves the player smoothly to that angle (either constant speed or accelerating, but preferably acceleration).

A secondary consideration is how to deal with multiple clicks. I'm currently thinking it moves to click1, then moves to click2, etc. The other possibility is always go towards the latest click.

I'm struggling to understand how to deal with angles, so help on any stage of this problem is most welcome.

You can get the location of a mouse click in world space by calling Camera.ScreenToWorldPoint on the current mouse position. Since the centre of the circle is at <0,0,0> this location can also be used as a direction vector.

If the player needs to stay exactly the same distance from the centre, you could simplify things by putting the player into a parent object at a set distance from the anchor point. Then, instead of using transform.RotateAround, you could just rotate the parent object to move the character around. It is straightforward to make a rotation from the clicked direction vector using Quaternion.LookRotation. You can sweep smoothly between the player's current rotation and the new rotation using Quaternion.Slerp.