# Two Points Rotating Around Circle?

Currently I am working on a 2D game just like duet game, it is my first game (Unity 2D).

When I press left key both points rotate fine. But when I press right, the points are not rotated.

So my problem is why do both points rotated only in one direction

Code:

public class TouchControll : MonoBehaviour
{
float movespeed = 3;
float angle = 45;

void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))   // when i m press leftarrow both point should be rotate fine
{
transform.Rotate(Vector3.forward * Time.deltaTime * Input.GetAxis("Horizontal") * angle * movespeed);
Debug.Log("moveleft");
}

if (Input.GetKey(KeyCode.RightArrow))  // problem is here when i m press right arrow key both point are not rotated
{
transform.Rotate(Vector3.forward * Time.deltaTime * Input.GetAxis("Vertical") * angle * movespeed);
Debug.Log("moveright");
}
}
}


Output:

create a empty gameobject: first circle second circle

• Please clarify which platform and input device you are using. – Theraot Jun 26 at 21:29
• @Theraot i m making game for android ,i m edit my question and when i m press left key both point rotated fine but problem is here when i m press right then point are not rotated thanks for replay plzz help?? – jishan nuran Jun 27 at 16:37

You code does not seem right for Android.

• Input.GetKey in intended to work with a physical keys (see How i can control button input android?). Instead you probably want to work with touch input. See Input.GetTouch.

• I have no idea what you are mapping at Input.GetAxis("Horizontal") and Input.GetAxis("Vertical"), however I would expect to use a single axis for rotation in both directions. Perhaps Input.GetAxis("Vertical") is mapped to nothing and that is why it does not work.

If you want your second case to have rotation in the opposite direction to the what you have on the first case, I would suggest to have exactly the same code, but use -angle instead of angle.

Addendum: This is an example of what I mean:

void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.forward * Time.deltaTime * Input.GetAxis("Horizontal") * angle * movespeed);
Debug.Log("moveleft");
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.forward * Time.deltaTime * Input.GetAxis("Horizontal") * -angle * movespeed);
Debug.Log("moveright");
}
}


In this case both are on the "Horizontal" axis, which I am assuming you need there. However rotation on one direction uses angle and for the opposite direction it is -angle.

I want to reiterate that they are both using Input.GetAxis("Horizontal") in the example above.

Two other ideas:

• It is common to have Input.GetAxis("Horizontal") mapped left and right keys. Which means that you would implement this with a single block:

void Update()
{
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.forward * Time.deltaTime * Input.GetAxis("Horizontal") * angle * movespeed);
}
}


Why? Because it is the axis that handling the direction of the rotatiton.

• Alternatively, you may not want to use axis at all (try and see if that works for you the way you want):

void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.forward * Time.deltaTime * angle * movespeed);
Debug.Log("moveleft");
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.forward * Time.deltaTime * -angle * movespeed);
Debug.Log("moveright");
}
}


It is also possible that what you need to do is to remap the axis you have. You can do that in the Input Manager, go to the menu Edit > Project Settings > Input. There you can find the defined axis and map them to what you want.

• thanks for suggestion but you saay:single axis for rotation in both directions but how ?? – jishan nuran Jun 27 at 17:15
• plz help?? i m little bit mistake in my programme?? can u edit my code??plzz – jishan nuran Jun 27 at 17:28
• @jishannuran No, I can't edit your code. – Theraot Jun 27 at 17:39
• i m trying -angle. but still not solved my problem – jishan nuran Jun 27 at 18:02
• @jishannuran expanded answer. – Theraot Jun 27 at 18:17