# Managing character movement in 3D in AR

I'm working on an ARKit project where I need to manage the movement of an object (white box) on a plane (blue square).

The characteristics of the environment are :

• The box can move only in 2D along X and Z axis
• The plane can rotate in 3D from its center on the 3 axis
• The plane can be in movement in all directions in the ARWorld.
• the user can move around the plane in the all directions (obviously some positions will be difficult to achieve but as the plane can move, it could also be above or below the user).
• The user can rotate the device in his hands around the 3 axis of the device (defined by the EulerAngles of the device).

Movement of the box is handled through swipe movement on the device. Whatever the position of the user or the plane, a swipe has to move the box in the direction of the swipe relatively to what the user sees on the screen, which is not necessary the same direction in the coordinate space of the box (up on the device could be right in the plane if for example the user has moved 90° to the left of the plane, or if the plane has rotated 90° to the right with the user still in the original place, in the case of a starting point with the plane in front of the user as in the picture above). Possible combinations are infinite.

Intuitively, I would say that I need :

• to determine the position of the user (i.e. camera) in the coordinate space of the plane node
• to determine the new EulerAngles of the device also in the coordinate space of the plane node
• to simulate the position of the user on a virtual sphere (the one in the picture above with plane center as center of the sphere), with its new EulerAngles
• to define for each zone of the sphere, and range of camera new EulerAngles, a set of rules that would translate swipe movement on the device to real movement of the cube

Is there an easier solution to achieve that ?