I have 2 joysticks: 1 that moves forward and backward, and one that moves left and right (think RC car controller).
Each joystick works fine on their own, however, when I want to use both at the same time is where I’m running into issues. The first initiated joystick stays with the first touched finger, however when the second joystick is touched, with a second finger, it will then follow the movements of the first finger, unless I remove the second finger from the screen.
I’ve been at it for hours and all over the forums, and while I have made considerable improvements on what my code was doing to what it is currently doing, I still have yet to figure out how to use both joysticks without these kinds of issues.
I’m using the Unity Event System on my UI objects. The event types I’m using currently are “Pointer Down” and “Drag” with their respective scripted functions provided with this post.
void Update ()
{
for (int i = 0; i < Input.touchCount; i++)
{
touchID = Input.GetTouch(i);
}
myTransform.rotation = rotationControl;
}
public void TouchDown()
{
touchIndex = touchID.fingerId;
}
public void TouchDrag()
{
deltaTouchPos = Input.GetTouch(touchIndex).deltaPosition;
if (VerticalAxis)
{
rotatingAxisVar = rotatingAxisVar + (deltaTouchPos.y * tiltSpeed);
RotateOnXAxis();
}
if (HorizontalAxis)
{
rotatingAxisVar = rotatingAxisVar + (deltaTouchPos.x * tiltSpeed);
RotateOnYZAxis();
}
}