Search Unity

Tapping on a moving ball

Discussion in 'Android' started by fieryben, Sep 13, 2018.

  1. fieryben

    fieryben

    Joined:
    Jul 23, 2013
    Posts:
    7
    Here's the scenario:

    I have a UI element (ball) with a 2D collider, 2D rigidbody, and using graphic raycaster to get touch inputs (on the canvas). I add a force to the ball and it bounces around nicely with no friction against my static walls (ball has bounciness set to 1).

    Now, as soon as the ball starts moving quickly, it's almost impossible to get a "tap" on the ball. At slow speeds, it works fine (real life example: slow walk works and jogging is impossible even though I want it to sprint).

    Would I get better responsiveness to touch input on my ball if I remove the rigidbody, use update and transform to move, and use vector3.reflect for bounces? Or is there a better way to get good input on my fast moving ball?

    Thanks
     
  2. fieryben

    fieryben

    Joined:
    Jul 23, 2013
    Posts:
    7
    Welp, just wanting to close this up. Basically, I had my ball also serving as a button and letting the graphic raycaster activate it's on click events. But there were situations where I clicked on the ball, but the on click events didn't fire and my background element didn't pick it up, resulting in nothing happening when clicking on the semi-fast moving ball.

    I removed the button component and on click events and added code to the ipointerdownhandler and now I have no problems at all.