Search code examples
unity-game-enginetouchscreen

on screen joystick in unity 5


the joystick does not work as expected when i slide the joystick down the train moves up and vice versa when i push up train moves down.

I would like to reverse that please.

here is code

using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;

public class joystick : MonoBehaviour {
    public float TrainSpeed = 50;
    public float TrainRotateSpeed = 50;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
            transform.Translate(0f, 0f, TrainSpeed *           CrossPlatformInputManager.GetAxis("Vertical") * Time.deltaTime);
        transform.Rotate(0f, TrainRotateSpeed * CrossPlatformInputManager.GetAxis("Horizontal") * Time.deltaTime, 0f);

}

}


Solution

  • Add a minus before TrainSpeed:

     transform.Translate(0f, 0f, -TrainSpeed * CrossPlatformInputManager.GetAxis("Vertical") * Time.deltaTime);