Move to touch direction


I am creating a marble rolling game for android. I want the marble to roll to the direction of the touch.

I am looking for some advice abouth how to start.


I am guessing you’re using rigidbodies for this? In that case you can use Rigidbody.AddTorque and/or Rigidbody.AddForce. Just make sure to use a physics material that have a little bit of friction or it’ll spin on the spot or move without rolling.

I guess you can figure out the torque axis by rotating the direction vector (to your target) by 90 degrees.

For the location the ball should roll to, I suppose using Physics.Raycast would be a good starting point.

You could take a look at Unity ressources:

Unity iPhone Examples: Roll-a-Ball
Includes a scripts using a Rigidbody for the ball and the accelerator as an input for direction.

Standard Assets (Mobile): Control Setups
especially TapControl, also used in the Penelope tutorial: