I'm creating a jetpack (mobile) controller where left joystick is used to control forward and backward movements and right joystick is used to control rotation and upward movements. What I want is player to go upwards whenever user is touching the right joystick even if horizontal && vertical axes both return zero. So if there is a finger on the right joystick player goes up similar to GetButton or GetKey(some keycode).
Asked
Active
Viewed 1,044 times
0
-
1I'm confused. Is this a physical controller or UI elements functioning as controls? If we're talking about UI elements, just add some public function to your joystick class that returns true when the joystick is selected – bpgeck Oct 30 '16 at 00:27
-
Yes we are talking about UI element not physical controller. Problem is that I can't seem to find any method to return true if there is a finger on joystick. For example Input.GetAxis("HorizontalRotate") returns value of 0 even if there is no finger on the joystick so I can't use that. Input.GetButton("HorizontalRotate") returns false no matter what. – Jonathan Oct 30 '16 at 09:07
1 Answers
1
Hope this helps somebody in the future:
I found out there is OnPointerUp and OnPointerDown methods that can be used to check if joystick is pressed or not. Easiest way for me to use those were to change a few things in Standard Assets > Utility > Joystick.cs. This is how those methods look like after my modifications:
public void OnPointerUp(PointerEventData data)
{
transform.position = m_StartPos;
UpdateVirtualAxes(m_StartPos);
if (data.rawPointerPress.name == "MobileJoystick_right") {
rightJoystickPressed = false;
}
}
public void OnPointerDown(PointerEventData data) {
if (data.pointerEnter.name == "MobileJoystick_right") {
rightJoystickPressed = true;
}
}
So basically I just added the If-statements. Now I can access the rightJoystickPressed boolean from any other script to check if joystick is being pressed even if it is not moved.

Jonathan
- 325
- 2
- 3
- 24