Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 icywater · Nov 27, 2011 at 06:18 PM · inputjoysticksaxes

Problem setting up twin stick shooter for mobile device...

I have been trying to set up a scene where a cube moves when the left joystick is moved, and rotates when the right is moved. Basically I am trying to make a basic twin stick shooter.

Using some code provided here: http://answers.unity3d.com/questions/28790/twin-stick-shooter.html

     var moveSensitivity : float = 3.0;
 
 function Update() {
     var lh : float = Input.GetAxis("LeftStickHorizontal");
     var lv : float = Input.GetAxis("LeftStickVertical");
     var rh : float = Input.GetAxis("RightStickHorizontal");
     var rv : float = Input.GetAxis("RightStickVertical");
 
     //Assumes you're looking down the z axis
     transform.position += Vector3(lh, lv, 0.0).normalized * moveSensitivity
                           * Time.deltaTime;
 
     //Assumes you're looking down the z axis and that you are looking down on the avatar
     transform.LookAt(transform.position + Vector3(rh, rv, 0.0), -Vector3.forward);
 }

I set up my inputs up accordingly and made them x or y-axis only and the types to joystick. But for some reason it still does not work. I am not getting any errors from the editor.

I think the reason my cube isn't moving is because my rh and rl (etc) values are fixed at zero. How come they don't change from between 1 to -1 (when I move my joysticks) like they are supposed to.

All help is appreciated. Thanks

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

1 Reply

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

Answer by WillTAtl · Nov 27, 2011 at 07:00 PM

Possible I'm wrong here, but unless I'm mistaken you can't read on-screen thumbsticks through unity's usual Input.GetAxis() methods. The original question was using a physical game controller, specifically a 360 one; these are supported by the Input class, but at present virtual on-screen controls for touch-screen devices are not.

Assuming you're using the on-screen sticks from the standard mobile assets, you have to read their value by accessing the script for them and reading the horizontal and vertical values there. In the standard mobile assets there's also a script FirstPersonControl that uses the DualJoysticks prefab.

You'll want variables to reference the joystick objects, like so...

 var leftStick: Joystick;
 var rightStick: Joystick;

These can be assigned in the inspector by dragging the left and right stick objects to them. Then you access the stick's positions through the leftStick.position and rightStick.position, which are simply vectors. Specifically, "leftStick.position.x" would be the equivalent of "Input.GetAxis("LeftStickHorizontal")".

The example script is fairly well-commented, and should help you with any other problems you run into (assuming you don't find it good enough for your needs as-is!)

Hope this helps!

Comment
Add comment · Show 1 · 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 icywater · Nov 27, 2011 at 07:34 PM 0
Share

Thanks. $$anonymous$$akes sense.

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

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

How to check if a key is down in editor script 2 Answers

Move camera with mouse (2D) 1 Answer

The Mario Jump? 2 Answers

cannon script is not working, no errors. 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