- Home /
How can I make my car turn?
Hello guys. I can't get my car to turn on the android device. I managed to make it work on the computer with: BackLeft.motorTorque=-maxTorque * Input.GetAxis("Vertical"); BackRight.motorTorque=maxTorque * Input.GetAxis("Vertical"); FrontLeft.steerAngle=20 * Input.GetAxis("Horizontal"); FrontRight.steerAngle=20 * Input.GetAxis("Horizontal");
The Input.GetAxis(" ") doesn't seem to be working on android devices. I've set up buttons for gas, left and right, but I only managed to get the gas button to work with: transform.Translate(Vector3.forward*speed/100);
, but it moves weird. If you have an idea of how can I get the buttons to work on my android device please share it with me. Thanks in advance.
Answer by stefanlaza · Sep 09, 2013 at 11:21 AM
You can use the import mobile asset joystick or touchpad or you can code it your self with a guitexture and touchinput. Here is some basic code : just tag your player player and attach the script check axis and speed ...
using UnityEngine;
using System.Collections;
public class desnodugmemovement: MonoBehaviour {
public int speed = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.touches.Length <=0)
{
//some code
}
else
{
for(int i=0;i<Input.touchCount;i++)
{
if(this.guiTexture.HitTest(Input.GetTouch(i).position))
{
if(Input.GetTouch(i).phase == TouchPhase.Stationary)
{
GameObject player = GameObject.FindWithTag("Player");
player.transform.Translate(speed*Time.deltaTime, 0, 0); // - speed from axis * Time.deltatime so the object does not use framerate
}
}
}
}
}
}
Your answer
Follow this Question
Related Questions
android gui 0 Answers
How to make car AI using WheelColliders turn exactly 90 degrees? 0 Answers
How make a character jump using a UI Button and the void OnGUI? 0 Answers
Android Controls Help! 2 Answers
iOS / Android Steering 2 Answers