- Home /
Question by
$$anonymous$$ · Apr 20, 2019 at 04:25 AM ·
carreversescreen.widthtouchcountgettouch
I know how to turn car left and right, but I dont know how to reverse. please help. thanks.
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).position.x < Screen.width / 2)
{
rb.AddRelativeTorque(0, -speed * 2 * Time.deltaTime, 0);
}
if (Input.GetTouch(0).position.x > Screen.width / 2)
{
rb.AddRelativeTorque(0, speed * 2 * Time.deltaTime, 0);
}
}
this is how my car is turning left and right
touch left side of the screen to turn left, turn right side of the screen to turn right. now I want is, when you touch both side of the screen, it should reverse
so I tried
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).position.x < Screen.width / 2 && Input.GetTouch(0).position.x > Screen.width / 2)
{
rb.AddForce(transform.forward * -speed * 2 * 1.8f * Time.deltaTime);
}
}
doesnt work, then I tried
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).position.x < Screen.width / 2 && Input.GetTouch(1).position.x > Screen.width / 2)
{
rb.AddForce(transform.forward * -speed * 2 * 1.8f * Time.deltaTime);
}
}
still doesnt work
how do I detect touch on both side of the screen and reverse the car
thanks in advanced.
Comment
You should also try:
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).position.x < Screen.width / 2 && Input.GetTouch(1).position.x > Screen.width / 2)
{
rb.AddForce(transform.forward * -speed * 2 * 1.8f * Time.deltaTime);
}
else if (Input.GetTouch(0).position.x > Screen.width / 2 && Input.GetTouch(1).position.x < Screen.width / 2)
{
rb.AddForce(transform.forward * -speed * 2 * 1.8f * Time.deltaTime);
}
}
Your answer
Follow this Question
Related Questions
Random.Range with Lists problem. 3 Answers
How to use Input.GetTouch().phase properly 0 Answers
Transitioning from different number of touches causes behavior overlap 0 Answers
Car is moving backword with Up Arrow Key [Solved] 1 Answer
How do i make another car in my car game to drive and chase around my track? 0 Answers