- Home /
Move to touch direction
Hey,
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.
Thanks!
Answer by Statement · Dec 22, 2011 at 12:51 PM
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.
Thanks for the tip! How can I deter$$anonymous$$ate the map coordinates of a touch?
Use the raycast to figure out where it hit. You'll get a world position from it. Check the link I posted about it.
Answer by efge · Dec 22, 2011 at 01:17 PM
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.
http://unity3d.com/support/resources/files/Roll-a-Ball.zip
Standard Assets (Mobile): Control Setups
especially TapControl, also used in the Penelope tutorial:
http://unity3d.com/support/resources/tutorials/penelope
Your answer
![](https://koobas.hobune.stream/wayback/20220613062312im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Tap Control on Android 1 Answer
About unity's API for android? 2 Answers
Help with iphone/android touch controls 2 Answers
Unity 2D Mobile Game Drawing Mechanic 0 Answers