Hello, I am making a multiplatform game (Android and Windows) for my school project. I have recently started to use new Unity because of the new GUI which I really like. The game is basically Roll-a-ball ported to Android added mechanisms etc. Problem I have is using touch control. I want to use left thumb to control the camera and right thumb to control the ball with D-pad. When I am touching “Up(Forward) Arrow” everything is fine until I move the camera, then first touch is being ignored until I release it. Also, sometimes D-pad buttons get’s stuck in pressed state when I swipe over it.
This is the code attached to Player object. For reference:
Dopredu- Forward
Dozadu - Backward
Dolava - Left
Doprava -Right
Prepinac - Switch
void FixedUpdate()
{
cameraRelativeRight = cam.TransformDirection(Vector3.right);
cameraRelativeForward = cam.TransformDirection(Vector3.forward);
cameraRelativeLeft = cam.TransformDirection(Vector3.left);
cameraRelativeBackward = cam.TransformDirection(Vector3.back);
if (dopredu){Dopredu ();}
if (dozadu){Dozadu();}
if (dolava){Dolava();}
if (doprava){Doprava ();}
}
void Dopredu()
{
rigidbody.AddForce(cameraRelativeForward * speed * Time.deltaTime );
Debug.Log("Dopredu");
}
void Dozadu()
{
rigidbody.AddForce(cameraRelativeBackward * speed * Time.deltaTime );
Debug.Log("Dozadu");
}
void Dolava()
{
rigidbody.AddForce(cameraRelativeLeft * speed * Time.deltaTime );
Debug.Log("Dolava");
}
void Doprava()
{
rigidbody.AddForce(cameraRelativeRight * speed * Time.deltaTime );
Debug.Log("Doprava");
}
public void SetDirectionDopredu(bool prepinac)
{
dopredu = prepinac;
Debug.Log("Dopredu prepnute");
}
public void SetDirectionDozadu(bool prepinac)
{
dozadu = prepinac;
Debug.Log("Dozadu prepnute");
}
public void SetDirectionDoprava(bool prepinac)
{
doprava = prepinac;
Debug.Log("Doprava prepnute");
}
public void SetDirectionDolava(bool prepinac)
{
dolava = prepinac;
Debug.Log("Dolava prepnute");
}
}
Buttons settings:

And this is the script I use to move the camera, it’s in Java because I couldn’t write my own script in C# so I had to use and edit this one :-/
var target : Transform;
var distance = 10.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = 0;
var yMaxLimit = 85;
private var x = 0.0;
private var y = 0.0;
var xsign =1;
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}
function Update ()
{
var rotation = Quaternion.Euler(y, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
var forward = transform.TransformDirection(Vector3.up);
var forward2 = target.transform.TransformDirection(Vector3.up);
if (Vector3.Dot(forward,forward2) < 0)
{xsign = -1;}
else
{xsign =1;}
for (var touch : Touch in Input.touches) {
/*"&& touch.position.x<Screen.width/2" part doesn't really have to be there but I couldn't find any other way how to disable camera movement when I wanted to use D-pad with right finger*/
if (touch.phase == TouchPhase.Moved && touch.position.x<Screen.width/2) {
x += xsign * touch.deltaPosition.x * xSpeed *0.02;
y -= touch.deltaPosition.y * ySpeed *0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
rotation = Quaternion.Euler(y, x, 0);
position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
Here is how the game looks like:
