Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 valecarlos · Aug 08, 2015 at 02:07 PM · joystick

Unity 5 Cross Platform Joystick position

Hi all, I'm developing a simple arcade game in 2d for which i need a Joystick, I've read some forums and watched some tutorials on how to use it, however for Unity 5's standard assets>CrossPlatformInput -I imported them from Assets>Import Package>CrossPlatformInput- I can seem to figure how to get the position of the Joystick to make my ship move around in the position towards the joystick is move.

My problem is, there is no 'Position' variable in the Joystick script for this version, so I have no idea how to actually get it. pardon me if the question seems dumb, I'm pretty much a beginner.

Also some details, I'm programming every script with JavaScript, and the CrossPlatformInput scripts are C#.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by legion_44 · Aug 08, 2015 at 02:11 PM

Just use CrossPlatformInputManager.GetAxis("Horizontal" or "Vertical"); (you need to import UnityStandardAssets.CrossPlatformInput namespace)

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 valecarlos · Aug 08, 2015 at 03:13 PM 0
Share

Thank you so much!, it was exactly what I was looking for, although I don't know exactly how does in know that i'm trying to get the joystick's axis?, i mean what if there's other joystick on the scene?, anyway I will post my piece of code as another answer. can't thank you enough, I was stuck for days!

avatar image legion_44 · Aug 08, 2015 at 03:19 PM 0
Share

@valecarlos On the Joystick script in the inspector you can set the vertical and horizontal axes names so if you have two sticks you can name axes on first like "walk_horizontal" and "walk_vertical" and on other "look_horizontal" and "look_vertical" then you use these names in the script.

avatar image
0
Wiki

Answer by valecarlos · Aug 08, 2015 at 04:04 PM

thanks to @fapwel here is my code: the ship is facing to the right hand side of the screen and the language is Javascript, although the Assets are C#, since in Javascript we don't use namespaces i used the whole path when declaring the variables

var joystick: UnityStandardAssets.CrossPlatformInput.Joystick; function FixedUpdate () { var joystickHorizontal = UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager.GetAxis("Horizontal"); var joystickVertical = UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager.GetAxis("Vertical"); if (joystickHorizontal != 0 && joystickVertical != 0) { var angle = Mathf.Atan2(joystickVertical , joystickHorizontal ) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); }

the joystick is dragged from the Hierarchy to the variable joystick in the inspector

hope it helps people with the same problem!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Joystick Problems 1 Answer

C# Clamp joystick rotation 0 Answers

Why does pressing joystick button 0 also trigger joystick button 1? 1 Answer

late response mobile joystick crossPlatformInput 1 Answer

stay the rotation in character 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