简体   繁体   中英

Touch pad as mouse input control

I modified the Roll-a-Ball tutorial to take touch pad input instead of controller input by changing these lines:

float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");

to this:

float moveHorizontal = Input.GetAxis ("Mouse X");
float moveVertical = Input.GetAxis ("Mouse Y");

This works perfectly on my Macbook track pad and the control is very smooth but on the Gear VR touch pad control is very erratic. (eg the ball often moves in completely the opposite direction from a swipe)

Can anyone tell me if there is something else I can do to make control smoother?

This worked for me:

if(Input.GetAxis("Mouse Y") != 0)
  {
      scrollValue.value += ((Input.mousePosition.y - 720) / 720);
  }

It checks if the user is trying to scroll the touchpad by checking the Mouse Y axis but then increments the scrollbar value by the mouse position relative to the default starting position that the touchpad always resets to (which is y=720) instead of using the Mouse Y axis value. if you're trying to scroll horizontally you'll want to use x instead of y and change 720 to 1280 since that is the default x position the touchpad uses.

The touch pad as a mouse approach in GearVR unity is misleading. When you have a mouse, the cursor position ( Input.position ) is moving from one place to another - but in GearVR, the mouse teleports to the center of the screen on each mouse/touch down. You have to use relative positions from each mousedown and add them for this kind of behaviour you want.

Oh and as far as I know, there is no way to check which part of the touch pad was touched by the user - it always registers as center and further movement is relative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM