# Transform.RotateAround with Joystick Rotation

I want to rotate one object around another, so that it matches my current joystick rotation. I know Transform.RotateAround does this but I can't seem to find a way to match it with my joystick rotation.

This is my code so far:

void Update()
{
joystick = InputManager.ActiveDevice;

moveInput= joystick.RightStickX;

if(currentState != CoreplayerState.stager) {
RotateChar();
}
}

public void RotateChar() {
transform.RotateAround(target.position, zAxis, moveInput * rotateSpeed);
transform.rotation = target.rotation;
}

• I notice at the moment you're only using the x component of the joystick input - so pointing right will rotate counter-clockwise about the z axis, and pointing left will rotate clockwise. Is this what you want, or do you want to rotate to the angle the joystick is currently pointing? (eg. if I point my joystick diagonally up & right, should the object rotate to sit above & to the right of its pivot and stop at that point?) – DMGregory Dec 3 '19 at 1:09
• Yeah I want it to work exactly as you pointed out, I just did not even try to map the vertical axis on the joystick because I never found a way to match my joystick position so I ended up only using the X axis of my joystick. – Adrian Moreno Dec 3 '19 at 1:34

We can think of the x, y input on the joystick as just another vector in our game world. Transforming it through the pivot lets you match the plane of rotation to the orientation of the pivot.

How's this work for your use case?

public class JoystickMatch : MonoBehaviour {

public Transform pivot;

void Update() {
var joystick = InputManager.ActiveDevice;
var heading = new Vector2(joystick.RightStickX, joystick.RightStickY);