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 Domain · Jan 18, 2014 at 02:37 AM · androidmobilejoystick

How to use joystick Unity Mobile?

I'm brand new to the mobile arena. I've got a simple game where you roll around a ball using the arrow keys (by using AddForce to the sphere's rigidbody), but I want this game to be for android. So I've set the settings and all that, I have a joystick on the game screen, I just don't know how to use it to move the ball. What values do I access to find the position of the joystick? I've had a lot of trouble trying to figure this out... Thanks.

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 jorjdboss · Jan 18, 2014 at 04:32 AM 0
Share

Can you be more specific about which joystick you're using? The one from the unity standard mobile package is not recommended for mobile because it uses GUITexture? If you got it from another source, look at the source code and find out the property to which the joystick output value is stored. If you can't understand any of this, probably you are new to Unity's way of coding.

avatar image Domain · Jan 18, 2014 at 04:45 AM 0
Share

I'm using the standard mobile package... if it's not recommended, what do you recommend I use?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jorjdboss · Jan 18, 2014 at 05:53 AM

First, create a joy stick base and a stick(use a cube or sprite, whatever), color them differently, make the stick 1/4th the size of the base. & parent the stick to the joy base.

Considering only the first touch, here's some pseudo code:

 // attach this script to the joystick base
 if(touchcount  = 1)
 {
   desiredStickLocalPosition = touch position - joy base position
   clamp desiredStickLocalPosition magnitude to joystick limits
   stick.localposition = desiredStickLocalPosition
 }

You may want to consider a package like Prime31's UIToolKit(free) or 2d toolkit(paid) to handle multi touch because you will end up needing it when you add other buttons.

I haven't coded this myself but I've tried make it understandable, hope it helps.

Comment
Add comment · Show 2 · 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 Domain · Jan 18, 2014 at 07:07 AM 0
Share

I'm just looking for the code that shows the current position of the joystick... aka joystick.position.x or something like that. But I will look into UITool$$anonymous$$it, thank you.

avatar image jorjdboss · Jan 18, 2014 at 07:40 AM 0
Share

For the output you would want a normalised value(-1,1) for each axis.

 output = stick.localposition / joystick limits

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

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

Rotate GameObject Z axis only relative to Joystick 0 Answers

Mobile joystick not moving player 0 Answers

How do I make on screen buttons in Android? 4 Answers

Porting simple game to android (Problem -> Controller) 0 Answers

GUI Joystick 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