• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by shygeek · Jun 25, 2014 at 12:28 PM · gameobject3dswipe

Football penalty game- Move gameobject in direction of swipe with force

Hello !! I want to make a game in which the user swipes the ball (like kicking the football) and the goalkeeper tries to save it. I also want to swipe the ball in the direction of swipe and also force. In my below code it only checks upward swipe. Can anyone help me how to proceed ?

 var gravity : float = 20.0;
 
 var dis:float=20.0;
 
 var uptest:boolean=true;
 
 var downtest:boolean=true;
 
 var StartPos:Vector2;
 
 var finid:int=-1;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Start()
 {
 
   Physics.gravity = Vector3(0,-25,0);
 
 }
 
 function Update () {
 
     for(var touch:Touch in Input.touches)
         {
             var pos = touch.position;
             if (touch.phase == TouchPhase.Began && finid == -1)
             {
                 finid = touch.fingerId;
                 StartPos = pos;
             }
             else if (touch.fingerId == finid)
             {
                 var delta = pos - StartPos;
                 if (touch.phase == TouchPhase.Moved && delta.magnitude > dis)
                 {
                     finid = -1;
                     if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y))
                     {
                     //
                     }
                     else
                     {
                         if (uptest && delta.y > 0)
                         {
                             
                             //upswipe
                         }
                            
                         else if (downtest && delta.y < 0)
                             {
                                     //downswipe
                             }
                     }
                    
                 }
                 else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                     finid = -1;
             }
         }
         }

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image roojerry · Jun 25, 2014 at 12:44 PM 0
Share

What is your question?

avatar image shygeek · Jun 25, 2014 at 12:56 PM 0
Share

I have a code which just detects upward swipe. I want to modify this to move the gameobject in the direction of swipe with the force.

avatar image roojerry · Jun 25, 2014 at 12:58 PM 0
Share

What have you tried?

avatar image Xitech_ · Jun 25, 2014 at 12:59 PM 0
Share

Detect the first touch position.y and compare it with the touch endpoint.position.y Now you now how much force you can give the ball to either left or right.

avatar image shygeek · Jun 25, 2014 at 01:01 PM 0
Share
 var anglex : float;
 var angley : float; 
 var elevationAngle : Vector3; 
  function Awake () {
  if (ScreenOrientation.Landscape) 
  {
  Screen.orientation = ScreenOrientation.LandscapeLeft;
  } 
  else 
  { 
  Screen.orientation = ScreenOrientation.Portrait;
  }
 
  }
  
 function FixedUpdate ()
  {
  
         if(Input.touchCount>0 && Input.GetTouch(0).phase == TouchPhase.Ended) 
                    {
  
                         var touchdeltaposition: Vector2 = Input.GetTouch(0).deltaPosition;
                         anglex = touchdeltaposition.x * Time.deltaTime *2.0;
                         Debug.Log(anglex);
                         angley = touchdeltaposition.y * Time.deltaTime *5.0;
                         Debug.Log(angley);
  
                 elevationAngle = Vector3(anglex,angley,0); 
  
                 rigidbody.velocity = transform.TransformDirection(Vector3(anglex,angley,angley ));
                 var elevation : Vector3 = Quaternion.Euler(elevationAngle) * transform.forward; 
                 rigidbody.AddRelativeForce(elevation);
  
                  Debug.Log("touch end"); 
                       }
  
                }

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

3D object in uGUI 3 Answers

Unity 5: Clean way to manage dynamically created GameObjects 1 Answer

how to set an object on a path,how to set an object on a track 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

How to make only this red area clickable on the cube ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges