Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 cwcarlos123654 · Mar 17, 2018 at 05:14 PM · movementbuttonbugtouchmultitouch

Moving left and right touch problem

Hello guys, im making a simple game with a cube moving left and right when the user presses the left or right half of the screen. i put 2 invisible buttons on each side of the screen and the button actions are like this: alt text

I have this code: this is under update:

             //Left and Right buttons MOVEMENT
             if (movingLeft == true) {
                 rb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
             } 
             if (movingRight == true) {
                 rb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
             } 
         }

and the other:

 public bool MovingLeft
 {  
     get
     {
         return movingLeft;
     }
     set
     {
         movingLeft = value;
     }
 }
 public bool MovingRight
 {
     get
     {
         return movingRight;
     }
     set
     {
         movingRight = value;
     }
 }


 //Not pressing - only forward force
 public void SetVelocityZero()
 {
         movingLeft = false;
         movingRight = false;
 }

my problem is: When i press on the left button(cube goes left) and then without releasing it and press the right button i want the character to change direction. Now when im moving left i need to first release the button and then press the right ,Hello guys, im making a simple game with a cube moving left and right the code for my movind is this:

   Update()
 {
                 if (movingLeft == true) {
                     rb.AddForce (-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
                 } 
                 if (movingRight == true) {
                     rb.AddForce (sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
                 } 
 }


 public bool MovingLeft
 {  
     get
     {
         return movingLeft;
     }
     set
     {
         movingLeft = value;
     }
 }
 public bool MovingRight
 {
     get
     {
         return movingRight;
     }
     set
     {
         movingRight = value;
     }
 }

 public void SetVelocityZero()
 {
         movingLeft = false;
         movingRight = false;
 }


and for movement im using invisible buttons placed on left half of screen and the right half of the screen. The buttons have this actions: alt text

The thing im asking about is: When the user is holding left screen(the cube goes left) and without releasing it when he presses the right screen then the cube to change direction to right.

movementhelp.png (19.5 kB)
movementhelp.png (19.5 kB)
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 RobAnthem · Mar 17, 2018 at 05:49 PM 0
Share

Umm... why not just use the StandardAssets.Joystick? I've made custom touch pads in the past though, if you want to do it, you need to access the Input.Touches array and deter$$anonymous$$e the touch location. Usually that's just dividing screen width by 2 and if the touch positions X axis is greater the divisor, it's on the right side, if it is less than the divisor, it is on the left side.

Does that make sense?

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.

Follow this Question

Answers Answers and Comments

146 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 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 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

how to apply multiple Functionality like touch moves with Buttons move..? 0 Answers

MultiTouch issues 1 Answer

Unity Bug, Letting User To touch two UI Buttons as same time (simultaneously) 1 Answer

Unity InputField, how to select other GameObjects with ONE touch on mobile devices? 0 Answers

iPhone Multitouch 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