Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by IKilledKenny_2 · Dec 29, 2015 at 05:58 PM · collisionjoystickbuttonsjoysticks

Use Joystick Axis As Buttons?

Hello Unity3D.I have a question about joysticks?How can i make it that i can use the axis of my joystick as a button or buttons?For Example.I use a ps4 controller for my game and i want to use the right analog stick axis as a button like if i push the stick up and it would equal the jump button and if i push the stick down it would equal the block button if i push it to the right it would equal punch button if i push it to the left it would equal the projectile button.If anyone knows how to do this.Can you please tell me how?

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

3 Replies

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

Answer by bowloflol · Dec 30, 2015 at 02:00 AM

Go to Edit -> Input Settings and play around with the settings there. To actually use the inputs in a script you'll need to use strings, here's a small example.

 var playerMove  :   float = 5;
 
 function Update()
 {
     if (Input.GetAxis("Horizontal"))
     {
         transform.localPosition.x += playerMovement * Input.GetAxis("Horizontal") * Time.deltaTime;
     }
    
     if (Input.GetAxis("Depth"))
     {
         transform.localPosition.z += playerMovement * Input.GetAxis("Horizontal") * Time.deltaTime;
     }
 }
 

Comment
Add comment · 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 bowloflol · Dec 30, 2015 at 02:19 AM 0
Share

my bad it should be

 var player$$anonymous$$ovement  :   float = 5;
avatar image IKilledKenny_2 bowloflol · Dec 30, 2015 at 03:28 AM 0
Share

Wait but suppose if i want to use the analog stick for 4 buttons.Like as in Punch,$$anonymous$$ick,Block,Grab?

avatar image bowloflol · Dec 30, 2015 at 04:47 AM 0
Share

You can add, edit, delete and duplicate inputs to your hearts content. And an updated script for that would look something like this

 var player$$anonymous$$ovement  :   float = 5;
 var playerAttacks   :   float = 0;
  
 function Update()
 {
     if (Input.GetAxis("Horizontal1"))
     {
         transform.localPosition.x += player$$anonymous$$ovement * Input.GetAxis("Horizontal1") * Time.deltaTime;
     }
     
     if (Input.GetAxis("Depth1"))
     {
         transform.localPosition.z += player$$anonymous$$ovement * Input.GetAxis("Depth1") * Time.deltaTime;
     }
     if (Input.GetAxis("Horizontal2"))
     {
         if (Input.GetAxis("Horizontal2") == 1)
         {
             Jump;
         }
         if (Input.GetAxis("Horizontal2") == -1)
         {
             Block;
         }
     }
     if (Input.GetAxis("Depth2"))
     {
         if (Input.GetAxis("Depth2") == 1)
         {
             Punch;
         }
         if (Input.GetAxis("Depth2") == -1)
         {
             $$anonymous$$ick;
         }
     }
 }

avatar image
1

Answer by A_Li_N · Dec 30, 2015 at 05:46 AM

Take my following note with a grain of sand...I could have been mis-understanding how sensitivity works... Read more here: http://docs.unity3d.com/Manual/class-InputManager.html

A quick note that inputs have a sensitivity, meaning even a click of a key on a keyboard is not instanly '1' on the axis, it will build up from 0 to 1 based on the sensitivity.

Changing those '== 1' and '== -1' to '> 0' and '< 0' will make the action instant as soon as the axis is pressed. (or setting the sensitivity of the inputs to 0)

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 bowloflol · Dec 31, 2015 at 07:42 AM 0
Share

I didn't even think about that, you are absolutely correct, thank you.

avatar image
0

Answer by IKilledKenny_2 · Jan 03, 2016 at 10:15 PM

I Love You!Thank you so much =D!

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

37 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

Related Questions

I need to control my player using a joystick. I used the default joystick script in Unity, but i am not able to integrate it with the player. Please help. I am attaching the player script, its currently using keyboard input 0 Answers

Detecting joystick disconnect 2 Answers

Sprite is drawn over canvas element 0 Answers

Controller Stick Input "Snaps" 0 Answers

How can I listen for input from all joystick axes through c sharp code? 0 Answers


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