• 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
Question by lol_lol_lol · Jan 08, 2014 at 11:00 PM · androidmovementplayercontrollertouchpad

how do i move my player left and right using touch pad?

Hello everyone!

I am working on a 2d game for android. however i really can't seem to find out how to use a touchpad. I would like to have it so that if the x value increases my player goes one direction if it decreases the other direction. I really can't seem to find out how to do it. if you would be so kind to tell me what script goes on what item aswell that would be wonderfull.

Thanks in advance.

Comment

People who like this

0 Show 4
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 ShadoX · Jan 09, 2014 at 08:06 AM 0
Share

Don't know anything about mobile stuff, but the general idea would be to just check where the user touched the screen and which way the touch is going to increase/decrease the value of x. I'm assuming that you can get the coordinates of the touch so you'd probably want to just check where the touch started, where it is now and compare the two to figure out which way the user wants to move..

avatar image lol_lol_lol · Jan 09, 2014 at 11:57 AM 0
Share

i know but there are prefabs for it i reckon they would work but how do i use them? Please if anyone could help me it would be highly appreciated.

avatar image lol_lol_lol · Jan 09, 2014 at 01:25 PM 0
Share

Also i would like it that if you reach the borders of the invisible square in the bottom right where you move the player that it keeps going in that direction. just like a joystick.

avatar image lol_lol_lol · Jan 09, 2014 at 08:33 PM 0
Share

Please can someone please tell me how i use the prefab. i would like it to be on bottom right corner.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by HariKrishnan · Jan 09, 2014 at 01:09 PM

 #pragma strict
 //Variables..............
 
 var speed=0.05f;
 
 function Start () {
 
 }
 
 
 
 
 function Update () {
 
 if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
 // Get movement of the finger since last frame
 var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
 // Move object across XY plane
 transform.Translate (touchDeltaPosition.x *speed,0,0);
 
 
 
 }
 
 
 
 }
Comment

People who like this

0 Show 3 · 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
avatar image HariKrishnan · Jan 09, 2014 at 01:34 PM 0
Share

increase or decrease the x axis to move the object. GetTouch(o) method using to get the position after assign to touchDeltaPosition variable....

avatar image lol_lol_lol · Jan 09, 2014 at 10:08 PM 0
Share

I really want to use the touch pad or a joystick (prefab) so this wasn't really relevant. thanks anyways. but i allready knew this.

avatar image HariKrishnan · Jan 11, 2014 at 04:45 AM 0
Share

player setting using to get the input from joystick or GUI texture using to get the input that is easy way i think

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

20 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Touch Controls for mobile 1 Answer

Player Controller moves automatically forward. cant stop. 1 Answer

Player shaking when move (not the camera) 0 Answers

All Unity Engine games' controls not working 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