- Home /
Move object same direction as finger swipe on screen
Hi, I want to write a script in c# for a 2d object, in which I need to move object direction and speed as finger swipe on screen. I achieved to move object's speed as finger's speed swipe on screen, but now I want to move object direction (specifically Arc position like in paper through game paper move on same direction as finger swipe). I already searched on google but couldn't find help. Kindly share with me tutorial or any link or code any one who done this earlier. Thanks in advance.
Answer by Spinnernicholas · Nov 26, 2013 at 10:24 PM
http://docs.unity3d.com/Documentation/ScriptReference/Touch.html
Vector2 direction;
float speed;
if(Input.touches[0].phase == TouchPhase.Moved)//Check if Touch has moved.
{
direction = Input.touches[0].deltaPosition.normalized; //Unit Vector of change in position
speed = Input.touches[0].deltaPosition.magnitude / Input.touches[0].deltaTime; //distance traveled divided by time elapsed
}
Answer by Tristan3110 · Jun 29, 2019 at 09:17 AM
Hi i'm in a similar position to you , I'm just wondering if all u do is just copy and paste this in or is there anthing else i need to do.I just starting using unity for maybe about a 3 weeks so i'm very new , but need to know for my school Major work. Thanks !!!