Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Laundro · Oct 04, 2013 at 01:30 AM · mobiletouchjoystickguitexturemultitouch

How to stop second finger from manipulating position of gui joystick

I have been working on a 3D mobile app in Unity3D, but have recently come across an issue. I have a joystick that makes my character walk. The joystick is a gui texture that. I have boundaries set so you can't move the joystick all around the screen. It is set up so that when your finger moves outside the boundary, the joystick goes as far as it can go, and when you move your finger back, it continues moving along with your finger. This is good and all but I am going to set it up so that moving another finger along the right side of the screen rotates the camera. The issue happens when one finger is on the joystick and you put another finger on the right side of the screen. The joystick is manipulated by the second finger and even though it isn't touching the joystick it manipulates the position of it. This only happens if a finger is already touching the joystick and you place another finger somewhere else on the screen. I can not figure out how to stop it! Any help will be GREATLY appreciated :) here is my code

 #pragma strict
 var gui: GUITexture;
 var pixelInsetPosResSet: boolean = true;
 var playerCharacter: GameObject;
 
 function Start ()
 {
 guiPixelInsetResSet();
 gui.color.a=.1;
 gui.transform.position.z=1;
 }
 
 function JoystickGUIMove ()
 {
 // Detecting Touch
 if(Input.touchCount > 0 ){
 
     for(var i : int = 0; i < Input.touchCount; i++){
 
     var touch : Touch = Input.GetTouch(i);
 
     if( touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
     {
         pixelInsetPosResSet = false;
     }
 if(pixelInsetPosResSet == false)
 {
 // Moving GUI and Character
     gui.pixelInset.x = touch.position.x+Screen.width/(-1.78);
     gui.pixelInset.y = touch.position.y+Screen.height/(-1.63);
     gui.color.a=.5;
     if(gui.pixelInset.y > Screen.height/(-3.5))
     {
         playerCharacter.transform.position.z = playerCharacter.transform.position.z+(8*Time.deltaTime);
     }
     else if(gui.pixelInset.y > Screen.height/(-2.6))
     {
         playerCharacter.transform.position.z = playerCharacter.transform.position.z+(2*Time.deltaTime);
     }
     else if(gui.pixelInset.y < Screen.height*(-.475))
     {
         playerCharacter.transform.position.z = playerCharacter.transform.position.z-(2*Time.deltaTime);
     }
     if(gui.pixelInset.x > Screen.width/(-2.4))
     {
         playerCharacter.transform.position.x = playerCharacter.transform.position.x+(2*Time.deltaTime);
     }
     if(gui.pixelInset.x > Screen.width/(-2.4) && gui.pixelInset.y > Screen.height/(-3.5))
     {
         playerCharacter.transform.position.x = playerCharacter.transform.position.x+(5*Time.deltaTime);
     }
     if(gui.pixelInset.x < Screen.width/(-2.1))
     {
         playerCharacter.transform.position.x = playerCharacter.transform.position.x-(2*Time.deltaTime);
     }
     if(gui.pixelInset.x < Screen.width/(-2.1) && gui.pixelInset.y > Screen.height/(-3.5))
     {
         playerCharacter.transform.position.x = playerCharacter.transform.position.x-(5*Time.deltaTime);
     }
     //Setting boundaries
     if(pixelInsetPosResSet == false)
     {
         if((touch.position.y+Screen.height/(-1.63)) > Screen.height/(-4.5)) 
         {
         gui.pixelInset.y = Screen.height/(-4.5);
         }
         if((touch.position.y+Screen.height/(-1.63)) < Screen.height*(-.5))
         {
         gui.pixelInset.y = Screen.height*(-.5);
         }
         if((touch.position.x+Screen.width/(-1.78)) > Screen.width/(-2.6))
         {
         gui.pixelInset.x = Screen.width/(-2.6);
         }
         if((touch.position.x+Screen.width/(-1.78)) < Screen.width*(-.5))
         {
         gui.pixelInset.x = Screen.width*(-.5);
         }
         }
         else
         {
             pixelInsetPosResSet = true;
             pixelInsetPositionReset();
         }
         }
 
 
 pixelInsetPositionReset();
 
 }   
 }
 }
 
 function pixelInsetPositionReset ()
 {
 // Reseting Joystick position
 for(var i : int = 0; i < Input.touchCount; i++){
 
 var touch : Touch = Input.GetTouch(i);
 
 if(touch.phase == TouchPhase.Ended)
 {
     pixelInsetPosResSet = true;
     guiPixelInsetResSet();
 }
 }
 }
 
 function guiPixelInsetResSet ()
 {
 // Set width and height automatically
 if (pixelInsetPosResSet == true)
 {
 gui.pixelInset.width=Screen.width/8.5;
 gui.pixelInset.height=gui.pixelInset.width;
 // Set position automatically
 gui.pixelInset.x=Screen.width/(-2.25);
 gui.pixelInset.y=Screen.height/(-2.35);
 }
 }
 
 function Update ()
 {
 pixelInsetPositionReset();
 gui.color.a=.1;
 JoystickGUIMove ();
 }   
Comment
Add comment · Show 1
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 hamstar · Oct 04, 2013 at 09:39 AM 0
Share

I'm glad you posted this because I think I have the same issue. It seems that guiTexture.HitTest does not work like it should. For example, if I press on my button, the touch phase is TouchPhase.Began as expected. If I press outside the button nothing registers, implying HitTest is working. However, if I press inside the button and then drag outside, HitTest keeps returning true, no matter where my finger is on the screen.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by citizen_rafiq · Oct 04, 2013 at 09:21 AM

http://answers.unity3d.com/questions/527469/smooth-move-with-gui-button.html

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Multi touches problem 0 Answers

Android 2D multitouch joystick + buttons 0 Answers

Problem with multi touch[solved] 0 Answers

How does multi-touch work 1 Answer

Touch Crosshair problem. 1 Answer


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