Hi, I wrote this code to make the player turn on itself if I touch(clockwise right, anticlockwise left) the screen till it is game over. I also wanted that when I don’t touch the screen it also rotates at a less speed clockwise.
The problem is that when I touch on the left side of the screen the rotational speed is not the same as when I touch right.
There is the code :
public float moveSpeed = 75f;
public float moveS = 25f;
float movement = 0f;
public bool gameOver = false;
public static Movimento current;
bool destra = false;
bool sinistra = false;
void Awake()
{
if (current == null)
current = this;
}
// Update is called once per frame
void Update()
{
if (!gameOver)
{
movement = Input.GetAxisRaw("Horizontal");
if (Input.touchCount > 0)
{
int tocco = Input.touchCount;
int toc = tocco - 1;
Touch touch = Input.GetTouch(toc);
if (touch.phase == TouchPhase.Began)
{
if (touch.position.x < Screen.width / 2)
{
destra = true;
sinistra = false;
}
if (touch.position.x > Screen.width / 2)
{
destra = false;
sinistra = true;
}
}
}
else
{
destra = true;
sinistra = true;
}
}
}
private void FixedUpdate()
{
if (gameOver)
transform.RotateAround(Vector3.zero, Vector3.forward, 0f * Time.fixedDeltaTime * -moveSpeed);
if (!gameOver)
{
transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * -moveSpeed);
if (destra && !sinistra)
{
transform.RotateAround(Vector3.zero, Vector3.forward, -1 * Time.fixedDeltaTime * -moveSpeed);
}
else if (sinistra && !destra)
{
transform.RotateAround(Vector3.zero, Vector3.forward, 1 * Time.fixedDeltaTime * -moveSpeed);
}
else if (destra & sinistra)
transform.RotateAround(Vector3.zero, Vector3.forward, 1 * Time.fixedDeltaTime * -moveS);
}
}
destra means right
sinistra means left
thanks