# Rotation of an object parallel to another object.

Hi Unity community, I am making a simple iPhone game where the player will be swiping a sphere object to rotate it, the controls for the rotation work great but I can’t find a working way to have the player move in the relative direction the globe would be rotating in. For example, I had it set so the little character would rotate to the point of the initial tap on the screen, now that would work fine if the ‘swipe’ were to match the direction of the character, but looks wrong if you were to swipe down, and the character is facing diagonal. I hope the picture explains what I need to achieve better.

So basically, if the player swipes the globe going top to bottom, the character should also face up as that’s the direction he’s running in, not at where the finger press initially starts which is my current method.

I would try the following:

1- When the touch begins, create an empty game object (the “Tracker”) at the player position and child this object to the planet.

2- Keep track of the Tracker movement, and make the player look in the opposite direction until the touch ends.

The code could be something like this (attached to the player):

``````private var tracker: Transform;

function Update(){
if (Input.touchCount > 0){
switch (Input.GetTouch(0).phase){
case TouchPhase.Began:
if (!tracker){ // if Tracker doesn't exist yet...
tracker = new GameObject("Tracker").transform; // create it
}
tracker.position = transform.position; // move it to the player position
break;
case TouchPhase.Move:
var dir: Vector3 = tracker.position - transform.position;
dir.y = 0; // keep only the horizontal direction
// if moved enough, player looks in the opposite direction:
if (dir.magnitude > 0.1) transform.forward = -dir;
break;
}
}
}
``````

NOTE: This code assumes that world Y is the character’s vertical direction, thus the image you’ve posted is the XZ plane, with Y pointing to our noses.

I will get back to you when I can check this, thanks for the post (: