• 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 /
  • Help Room /
avatar image
0
Question by GhostDre · Jun 17, 2016 at 09:01 PM · movementdirectionobjectsmultipleswipe

[HELP] Swiping multiple objects from a raycast

Hi there I will try to explain this as best as I can. I was working on a Touch Logic script where as to when you touch an object and swipe it a certain way it will go that direction. Now the kicker is that I have multiple objects that are on the screen and every time I swipe "Up" only one object will move up constantly. I think I need a raycast but Im not sure where to put it. I tried in certain locations but I'm still getting the same results. Please help me I appreciate it.

Touch Logic Script:

     public GameObject upWall;
 
     Ray ray;
     RaycastHit hit;
 
     public float maxTime;
     public float minSwipeDist;
 
     float startTime;
     float endTime;
 
     Vector3 startPos;
     Vector3 endPos;
 
     float swipeDistance;
     float swipeTime;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.touchCount > 0) { //(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {
 
             Touch touch = Input.GetTouch(0);
 
             if (touch.phase == TouchPhase.Began)
             {
 
                 startTime = Time.time;
                 startPos = touch.position;
              
             }
             else if (touch.phase == TouchPhase.Ended ) {
 
                 endTime = Time.time;
                 endPos = touch.position;
 
                 swipeDistance = (endPos - startPos).magnitude;
                 swipeTime = endTime - startTime;
 
                 if (swipeTime < maxTime && swipeDistance > minSwipeDist) {
                     swipe();
                 }
             }
         }
 
     }
 
     void swipe() {
 
         Vector2 distance = endPos - startPos;
         if (Mathf.Abs(distance.x) > Mathf.Abs(distance.y)) {
             Debug.Log("Horizantal Swipe");
 
             if (distance.x > 0) {
                 Debug.Log("Right Swipe");
             }
 
             if (distance.x < 0)
             {
                 Debug.Log("Left Swipe");
             }
 
         }
         else if(Mathf.Abs(distance.x) < Mathf.Abs(distance.y)) {
             Debug.Log("Vertical Swipe");
 
 
             if (distance.y > 0)
             {
                 Debug.Log("Up Swipe");
                 upWall.GetComponent<Upwall>().MovementUp();
             }
 
             if (distance.y < 0)
             {
                 Debug.Log("Down Swipe");
             }
 
         }
 
 
     }
 }
 

This is the movement script of wall moving up:

     public float speed = 100f;
     public float shift = 1f;
 
     public float maxPos = 3.5f;
 
     Vector3 position;
 
     bool currentPlatformAndroid = false;
 
     void Awake() {
           
     }
 
     // Update is called once per frame
     void Start()
     {
         position = transform.position;
 
        
 
     }
 
     void Update()
     {
 
       
 
             float translation = Input.GetAxis("Vertical") * speed * Time.deltaTime;
             position.y = Mathf.Clamp(position.y, 0, 2.4f);
 
             translation *= Time.deltaTime;
             transform.Translate(0, translation, 0);
 
             //transform.position = position;
 
             //(new Vector3(position.x * shift * Time.deltaTime, 0, 0));
             transform.Translate(Vector3.left * shift * Time.deltaTime);
         
     }
 
     public void MovementUp() {
 
         transform.Translate(Vector3.up * 75 * Time.deltaTime);
     }
 }
 
Comment
Add comment · Show 2
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 GhostDre · Jun 17, 2016 at 10:57 PM 0
Share

***bumping

avatar image GhostDre · Jun 20, 2016 at 07:42 PM 0
Share

***bumping

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

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Swipe camera rotation controller (HELP) 0 Answers

How can I incorporate a Rotation Towards the Mouse Position into this Script? I Tried. 0 Answers

Object movement algorithm 0 Answers

How do I rotate my object back to the world's up direction whilst keeping it's forward direction? 0 Answers

Virtual camera odd behaviour. Scriptting noob questions 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